如何转换日期格式 [英] How to convert a date format

查看:124
本文介绍了如何转换日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ID CardDate

001 09/01/2010
002 08/05/2010

表中的日期格式:(mm/dd/yyyy)

DateFormat in the table : (mm/dd/yyyy)

我想在cardDate& systemDate

I want to make a datediff between cardDate & systemDate

查询

Select id, datediff(carddate, curdate()) as actualdate group by id from table

由于carddate格式错误,因此上面的查询在Actualdate列中显示了空值.

The above query is showing a null value in actualdate column becuase carddate format is wrong.

如何更改yyyy-mm-dd这样的Carddate格式

How to change the Carddate format like this yyyy-mm-dd

推荐答案

使用:

SELECT t.id,
            DATEDIFF(STR_TO_DATE(t.carddate, '%m/%d/%Y'), CURDATE)
   FROM TABLE t

我认为查询中不需要使用GROUP BY-位置不正确,如果仍然需要的话,应该在FROM子句之后(以及WHERE).

I don't see the need for the GROUP BY you have in your query - it's in the wrong spot, should be after the FROM clause (and WHERE for that matter) if you still want it.

这篇关于如何转换日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆