the following script...
<?php
$times = array(
'2004-04-04 00:31:00-06',
'2004-04-04 01:00:00-06',
'2004-04-04 01:59:59-06',
'2004-04-04 02:00:00-06',
'2004-04-04 03:00:00-06',
);
for ($i = 0; $i < count($times); $i++)
{
$s = $times[$i];
$time_t = strtotime($s);
print "strtotime('$s' ) = $time_t\n";
print "date('r', $time_t) = \"" . date('r', $time_t) . "\"\n";
print "\n";
}
?>
generates this output:
strtotime('2004-04-04 00:31:00-06') = 1081060260
date('r', 1081060260) = "Sat, 3 Apr 2004 23:31:00 -0700"
strtotime('2004-04-04 01:00:00-06') = 1081062000
date('r', 1081062000) = "Sun, 4 Apr 2004 00:00:00 -0700"
strtotime('2004-04-04 01:59:59-06') = 1081065599
date('r', 1081065599) = "Sun, 4 Apr 2004 00:59:59 -0700"
strtotime('2004-04-04 02:00:00-06') = 1081069200
date('r', 1081069200) = "Sun, 4 Apr 2004 03:00:00 -0600"
strtotime('2004-04-04 03:00:00-06') = 1081069200
date('r', 1081069200) = "Sun, 4 Apr 2004 03:00:00 -0600"
date() seems to be picking rather arbitrary timezones for output.
Secondly, as best as I can tell, the fourth output is just patently WRONG
(or I'm too dense to see what's going on, but I don't think so).
I often want to calculate a time_t value at 00:00:00 (midnight) for an
arbitrary input time_t. I had been doing this as:
$midnight = strtotime(date( 'Y-m-d', $time_t));
but given the behaviour above, I don't think this works reliably. :(
The machine this is running on happens to be in MDT right now
(offset -06) and running PHP version 4.1.0. Can someone help me figure out
what the hell is going on here (or a *reliable* way to get a time_t value
for midnight of input strings of the form strtotime() handles)?
Thanks in advance.
-ej
<?php
$times = array(
'2004-04-04 00:31:00-06',
'2004-04-04 01:00:00-06',
'2004-04-04 01:59:59-06',
'2004-04-04 02:00:00-06',
'2004-04-04 03:00:00-06',
);
for ($i = 0; $i < count($times); $i++)
{
$s = $times[$i];
$time_t = strtotime($s);
print "strtotime('$s' ) = $time_t\n";
print "date('r', $time_t) = \"" . date('r', $time_t) . "\"\n";
print "\n";
}
?>
generates this output:
strtotime('2004-04-04 00:31:00-06') = 1081060260
date('r', 1081060260) = "Sat, 3 Apr 2004 23:31:00 -0700"
strtotime('2004-04-04 01:00:00-06') = 1081062000
date('r', 1081062000) = "Sun, 4 Apr 2004 00:00:00 -0700"
strtotime('2004-04-04 01:59:59-06') = 1081065599
date('r', 1081065599) = "Sun, 4 Apr 2004 00:59:59 -0700"
strtotime('2004-04-04 02:00:00-06') = 1081069200
date('r', 1081069200) = "Sun, 4 Apr 2004 03:00:00 -0600"
strtotime('2004-04-04 03:00:00-06') = 1081069200
date('r', 1081069200) = "Sun, 4 Apr 2004 03:00:00 -0600"
date() seems to be picking rather arbitrary timezones for output.
Secondly, as best as I can tell, the fourth output is just patently WRONG
(or I'm too dense to see what's going on, but I don't think so).
I often want to calculate a time_t value at 00:00:00 (midnight) for an
arbitrary input time_t. I had been doing this as:
$midnight = strtotime(date( 'Y-m-d', $time_t));
but given the behaviour above, I don't think this works reliably. :(
The machine this is running on happens to be in MDT right now
(offset -06) and running PHP version 4.1.0. Can someone help me figure out
what the hell is going on here (or a *reliable* way to get a time_t value
for midnight of input strings of the form strtotime() handles)?
Thanks in advance.
-ej
Comment