I'm doing something like this:
SELECT date_format(mydate, '%d/%m/%Y') FROM xyz;
When mydate is NULL, date_format returns 00/00/0000. This is correct, but how can I make it so that it returns NULL when the input is NULL?
I'm doing something like this:
SELECT date_format(mydate, '%d/%m/%Y') FROM xyz;
When mydate is NULL, date_format returns 00/00/0000. This is correct, but how can I make it so that it returns NULL when the input is NULL?
You can wrap this into a
IF
-Clause, like this:That said, if your variable
mydate
is not a date value, the query in your post should return(NULL)
anyway.Source: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html