tHud Posted July 21, 2010 Share Posted July 21, 2010 Hi, In order to display dates in a readable format (when accessing MySQL) I use this little function... function timechange($sqltime) { return date ("d-m-Y", strtotime ($sqltime)); } The only problem is, when the field is empty (0000-00-00) it returns 30-11-1999 Any thoughts on how I could correct this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/208449-return-an-empty-mysql-date-field-correctly/ Share on other sites More sharing options...
StathisG Posted July 21, 2010 Share Posted July 21, 2010 function timechange($sqltime) { if ($sqltime == '0000-00-00') { return 'whatever'; } else { return date ("d-m-Y", strtotime ($sqltime)); } } Quote Link to comment https://forums.phpfreaks.com/topic/208449-return-an-empty-mysql-date-field-correctly/#findComment-1089226 Share on other sites More sharing options...
tHud Posted July 21, 2010 Author Share Posted July 21, 2010 Sigh...! I had tried so many variants, the last of which was if (strtotime ($sqltime) == '0000-00-00') I think this shows a fundamentally flawed understanding on my part. Thank you very much - your help is much appreciated. Where do you guys learn php? By yourselves? Or at University? Would love to know Quote Link to comment https://forums.phpfreaks.com/topic/208449-return-an-empty-mysql-date-field-correctly/#findComment-1089282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.