chemicaluser Posted October 30, 2011 Share Posted October 30, 2011 Some of the dates (timestamp) in my database have a value of 0000-00-00 00:00:00 when I echo out the date - I see 1969-12-31 19:00 echo 'Date Added - ' . date("Y-m-d G:i ", strtotime($row['time_added'])).'<br/>'; anyone know why ...is it because 0000-00-00 is not a valid date? any way to make it display the words "n/a" instead of the 1969-12-31 Link to comment https://forums.phpfreaks.com/topic/250125-date-echoes-out-as-1969-12-31/ Share on other sites More sharing options...
silkfire Posted October 30, 2011 Share Posted October 30, 2011 Indeed, 0000-00-00 is not a valid date according to PHP. Strange thing though it should return 1970-01-01 because that's what the date 0 is equal to. Anyway you can make a simple check: if ($date == 0) echo 'N/A'; Link to comment https://forums.phpfreaks.com/topic/250125-date-echoes-out-as-1969-12-31/#findComment-1283524 Share on other sites More sharing options...
chemicaluser Posted October 30, 2011 Author Share Posted October 30, 2011 thanks, that did it ... but i have one more qustion if ($time_added == 0) echo 'Date Added - n/a <br/>'; if ($time_added != 0) echo 'Date Added - ' . date("Y-m-d G:i ", strtotime($row['time_added'])).'<br/>'; the second part does not work, if the time not equal to 0 - any ideas? and in my reading around i did find that Western Hemisphere = 31 Dec 1969 Eastern Hemisphere = 1 Jan 1970 Link to comment https://forums.phpfreaks.com/topic/250125-date-echoes-out-as-1969-12-31/#findComment-1283527 Share on other sites More sharing options...
chemicaluser Posted October 30, 2011 Author Share Posted October 30, 2011 also, sometimes when I echo it out (same page but on a different server) i see -0001-11-30 0:00 1969-12-31 19:00 Link to comment https://forums.phpfreaks.com/topic/250125-date-echoes-out-as-1969-12-31/#findComment-1283537 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.