简体   繁体   中英

How to convert a date format

Table

ID CardDate

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

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

I want to make a datediff between cardDate & systemDate

Query

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

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

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

Use:

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

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.

看看MySQL GET_FORMATSTR_TO_DATE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM