conditional formatting of from_unixtime

时间:2018-06-18 11:39:40

标签: mysql sql

I have a query that among other fields returns a due date and cutoff date. sometimes these field would be null and so, when converted like so:

 FROM_UNIXTIME(assignment.cutoffdate, '%d-%m-%Y %H:%i')

will display 01-01-1970 02:00. How can I display an empty string or some text like 'not available' in such cases? please note that using a "where date is not null" condition will not do because a need all results, including those with null in date fields.

1 个答案:

答案 0 :(得分:0)

只需使用IF语句:

IF(assignment.cutoffdate IS NULL, 'not available', FROM_UNIXTIME(assignment.cutoffdate, '%d-%m-%Y %H:%i'))