jandrews3 Posted July 22, 2012 Share Posted July 22, 2012 I'm just missing something stupid, I know I am, but I've been working on it for more than an hour. Why does the following code: $month = 3; $day = 9; print "M: ".$month."<br>"; print "D: ".$day."<br>"; $due = $month." / ".$day; print $due."<br>"; print date("M j", $due)."<br>"; yield the following output: M: 3 D: 9 3 / 9 Dec 31 AUGGHHH! Shouldn't the last line be "Mar 9"???? I know. I'm stupid but my brain fried after I accidentally deleted my quiz table with nearly 90 quizzes for my students ... and NO, I was too stupid to have backed it up. So ... I'm not all here right now. But I just can't figure what's going wrong with this script. Thanks! Link to comment https://forums.phpfreaks.com/topic/266098-php-date/ Share on other sites More sharing options...
Pikachu2000 Posted July 22, 2012 Share Posted July 22, 2012 date expects a unix timestamp, not a string. It's failing and returning the beginning of the Unix epoch (zero seconds), which works out to Dec 31, 1969. Link to comment https://forums.phpfreaks.com/topic/266098-php-date/#findComment-1363590 Share on other sites More sharing options...
Nyuszer Posted July 22, 2012 Share Posted July 22, 2012 you should use mktime() to convert your date to unix timestamp $due = mktime(0,0,0,$month,$day); print date("M j", $due); Link to comment https://forums.phpfreaks.com/topic/266098-php-date/#findComment-1363594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.