|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-03-07 07:39 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 10 23:00:01 2025 UTC |
Description: ------------ I'm not really fond of mktime() but I needed a way of taking two dates in MySQL format and seeing which date is older... ie: $date = "2007-03-01"; if ($date <= date('Y-m-d')) { print "Expired"; } else { print "Not Expired"; } I know you can't use dates like that in the condition so I used date('U') and mktime() to give me the seconds since the Unix Epoch but I decided to test using different date formats first just to see how mktime handles months and years that might or might not have leading zero's.. notice the difference in seconds with the year 08 vs. 07 please correct me if I'm doing something stupid here that I should not be doing. I don't quite understand Bug #25050 - is this the same situation? thanks for your time! Reproduce code: --------------- print "test1: " . date('U', mktime(0, 0, 0, 3, 1, 2008)) . "<br />"; // 3-1-2008 returned 1204261200 print "test2: " . date('U', mktime(0, 0, 0, 3, 1, 08)) . "<br />"; // 3-1-08 returned 951800400 print "test3: " . date('U', mktime(0, 0, 0, 03, 1, 2008)) . "<br />"; // 03-1-2008 returned 1204261200 print "test4: " . date('U', mktime(0, 0, 0, 03, 1, 08)) . "<br />"; // 03-1-08 returned 951800400 print "test5: " . date('U', mktime(0, 0, 0, 3, 1, 2007)) . "<br />"; // 3-1-2007 returned 1172638800 print "test6: " . date('U', mktime(0, 0, 0, 3, 1, 07)) . "<br />"; // 3-1-07 returned 1172638800 print "test7: " . date('U', mktime(0, 0, 0, 03, 1, 2007)) . "<br />"; // 03-1-2007 returned 1172638800 print "test8: " . date('U', mktime(0, 0, 0, 03, 1, 07)) . "<br />"; // 03-1-07 returned 1172638800 test1: 1204347600 test2: 951886800 test3: 1204347600 test4: 951886800 test5: 1172725200 test6: 1172725200 test7: 1172725200 test8: 1172725200 Expected result: ---------------- I expected to see: test1: 1204347600 test2: 1204347600 test3: 1204347600 test4: 1204347600 test5: 1172725200 test6: 1172725200 test7: 1172725200 test8: 1172725200 Actual result: -------------- instead I got: test1: 1204347600 test2: 951886800 test3: 1204347600 test4: 951886800 test5: 1172725200 test6: 1172725200 test7: 1172725200 test8: 1172725200