RE: [PHP] Most bizarre date problem ever
On 10 April 2004 16:11, Brian Dunning wrote: Check this out: I'm returning a list of the last 30 days, looping through i, subtracting it from $end_date where $end_date is 2004-04-10 00:00:00. I'm just trying to derive a timestamp $check_date for each iteration, like 1081321200. Here's the code within the loop: $check_date = mktime(0, 0, 0, substr($end_date, 5, 2), substr($end_date, 8, 2) - $i, substr($end_date, 0, 4), -1); Note that this works PERFECTLY for every date, and always has. Except for one particular day. When $end_date - $i is supposed to be April 4, the timestamp returned is -7262, which it thinks is 12/31/1969. This looks like a Daylight Savings timeshift bug on your system (and there are more of those around than you can shake a stick at!). Because of such problems, you should never use a time anywhere near the DST hour-change when you are calculating consecutive dates, and most especially not a time that could conceivably be shifted into the adjacent day (i.e. 00:00-00:59) -- always use something squarely in the middle of the day, such as midday: $check_date = mktime(12, 0, 0, substr($end_date, 5, 2), substr($end_date, 8, 2) - $i, substr($end_date, 0, 4), -1); Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Most bizarre date problem ever
On Apr 14, 2004, at 7:25 AM, Ford, Mike [LSS] wrote: Because of such problems, you should never use a time anywhere near the DST hour-change when you are calculating consecutive dates, and most especially not a time that could conceivably be shifted into the adjacent day (i.e. 00:00-00:59) It was the only way I could figure out how to write SQL to find all orders that were from a particular day (orders have a datetime field on them) - so I'm searching for everything greater than or equal to 00:00:00 and less than or equal to 23:59:59. I'd rather use SQL that just looks at the date and ignores the time portion, if there's any way to do that. - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Most bizarre date problem ever
On 10 Apr 2004 Brian Dunning wrote: Check this out: I'm returning a list of the last 30 days, looping through i, subtracting it from $end_date where $end_date is 2004-04-10 00:00:00. I'm just trying to derive a timestamp $check_date for each iteration, like 1081321200. Here's the code within the loop: $check_date = mktime(0, 0, 0, substr($end_date, 5, 2), substr($end_date, 8, 2) - $i, substr($end_date, 0, 4), -1); Note that this works PERFECTLY for every date, and always has. Except for one particular day. When $end_date - $i is supposed to be April 4, the timestamp returned is -7262, which it thinks is 12/31/1969. I don't see the same problem. This code: ?php $end_date = 2004-04-10; for ($i = 1; $i = 30; $i++) { $check_date = mktime(0, 0, 0, substr($end_date, 5, 2), substr($end_date, 8, 2) - $i, substr($end_date, 0, 4), -1); $strdate = date(m-d-Y, $check_date); print($check_date = $strdate\n); } ? Produces this output: 1081483200 = 04-09-2004 1081396800 = 04-08-2004 1081310400 = 04-07-2004 1081224000 = 04-06-2004 1081137600 = 04-05-2004 1081054800 = 04-04-2004 1080968400 = 04-03-2004 1080882000 = 04-02-2004 1080795600 = 04-01-2004 1080709200 = 03-31-2004 1080622800 = 03-30-2004 1080536400 = 03-29-2004 108045 = 03-28-2004 1080363600 = 03-27-2004 1080277200 = 03-26-2004 1080190800 = 03-25-2004 1080104400 = 03-24-2004 1080018000 = 03-23-2004 1079931600 = 03-22-2004 1079845200 = 03-21-2004 1079758800 = 03-20-2004 1079672400 = 03-19-2004 1079586000 = 03-18-2004 1079499600 = 03-17-2004 1079413200 = 03-16-2004 1079326800 = 03-15-2004 1079240400 = 03-14-2004 1079154000 = 03-13-2004 1079067600 = 03-12-2004 1078981200 = 03-11-2004 Tested on PHP 4.3.4 on Win2K. -- Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Most bizarre date problem ever
* Thus wrote Brian Dunning ([EMAIL PROTECTED]): $check_date = mktime(0, 0, 0, substr($end_date, 5, 2), substr($end_date, 8, 2) - $i, substr($end_date, 0, 4), -1); Note that this works PERFECTLY for every date, and always has. Except for one particular day. When $end_date - $i is supposed to be April 4, the timestamp returned is -7262, which it thinks is 12/31/1969. Can somebody PLEASE tell me how the above code manages to produce -7262, when it's always worked properly for every other day in history? Works fine for me: $end_date = '2004-04-05'; $i = 1; $check_date = mktime(0, 0, 0, substr($end_date, 5, 2), substr($end_date, 8, 2) - $i, substr($end_date, 0, 4), -1); echo date('r', $check_date), \n, $check_date; output: Sun, 4 Apr 2004 00:00:00 + 1081036800 Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php