djsl Posted August 20, 2009 Share Posted August 20, 2009 here is what I have I am sending a timestamp using now to a table that is set to datetime through a form this is the entry in the table 2009-08-20 09:47:11 I use this to echo in html and it shows up good $notesline1date=mysql_result($result,$i,"notes_line_1_date"); $notesline1datenew = date('m j Y', strtotime($notesline1date)); <? echo $notesline9datenew; ?> the problem I am having is when no date has been set the table is 0000-00-00 00:00:00 but the echo shows up as 11 30 -0001 I would like it to be blank, and is there a better way of doing this I am figuring things out as I go. thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/171166-solved-weird-date-format-result/ Share on other sites More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 $notesline1datenew = 'no date'; if (!is_empty_date($date)) { $notesline1datenew = date('m j Y', strtotime($notesline1date)); } function is_empty_date($date) { return preg_match('/[0]{4}-[0]{2}-[0]{2} [0]{2}:[0]{2}:[0]{2}/', $date); } Quote Link to comment https://forums.phpfreaks.com/topic/171166-solved-weird-date-format-result/#findComment-902619 Share on other sites More sharing options...
djsl Posted August 20, 2009 Author Share Posted August 20, 2009 thanks for the help I tried it and it works great, the only problem that I have now is that I have multiple lines of dates that I want to show when I add the script to all the lines I get the following Fatal error: Cannot redeclare is_empty_date() (previously declared in........ thanks Quote Link to comment https://forums.phpfreaks.com/topic/171166-solved-weird-date-format-result/#findComment-902666 Share on other sites More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 Fatal error: Cannot redeclare is_empty_date() (previously declared in....... This error means that you have defined is_empty_date() multiple times, like: function is_empty_date() .. a few lines lower: function is_empty_date() .. Make sure function is_empty_date() only appears once. Quote Link to comment https://forums.phpfreaks.com/topic/171166-solved-weird-date-format-result/#findComment-902680 Share on other sites More sharing options...
djsl Posted August 20, 2009 Author Share Posted August 20, 2009 thanks I found I had accidently put it in there more than once. Works great now Quote Link to comment https://forums.phpfreaks.com/topic/171166-solved-weird-date-format-result/#findComment-902697 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.