View Full Version : Handling empty datetimes
11-20-2007, 03:38 AM
When a datetime field in the DB is empty, it returns 0000-00-00 00:00:00. When I display this field I don't want anything to show. Other than doing an IF...then check for that pattern, is there a better way to convert this to a blank?
11-20-2007, 03:53 AM
I can't think of a better way than IF.
11-20-2007, 04:18 AM
I just wasn't sure if there was a built-in method or something else that I could use.
11-20-2007, 04:29 AM
IF() is built-in. :p You may want to post this in, or ask it to be moved to, the MySQL forum.
11-20-2007, 04:24 PM
You can also use IFNULL() to give it a more descriptive result such as 'None' or 'N/A'.
11-20-2007, 06:21 PM
I was going to suggest that, but I tested it and MySQL doesn't seem to consider '0000-00-00 00:00:00' to be NULL, even if the field is datetime.
11-20-2007, 06:27 PM
I have to admit I didn't test it. I was drawing on Oracle experience (where such a date would be NULL). I wonder why MySQL doesn't consider that NULL.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.