tags:

views:

19

answers:

2

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

A: 

Take a look at MySQL GET_FORMAT and STR_TO_DATE

RC
+1  A: 

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.

OMG Ponies