php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33456 strtotime losing 2 hours
Submitted: 2005-06-24 00:13 UTC Modified: 2005-06-30 10:37 UTC
From: serge at skycomp dot ca Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 4.3.11 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: serge at skycomp dot ca
New email:
PHP Version: OS:

 

 [2005-06-24 00:13 UTC] serge at skycomp dot ca
Description:
------------
It seems that strtotime is loosing time.  I'm loosing 2 hours on every call to it and I'm not sure why.

The issue seems to be with the "at" text in the format string but I am unsure why the text "at" would make the timestamp lose exactly 2 hours.

Reproduce code:
---------------
<?
$_REQUEST['event_time']=strftime('%A, %B %e %Y at %r',strtotime($_REQUEST['event_time']));
?>
<form action='<?=$_SERVER['PHP_SELF']?>'>
<input size='50' type='text' name='event_time' value='<?=$_REQUEST['event_time']?>'
<input type="submit">
</form>

Expected result:
----------------
The output should be the formated representation from what was inputted.  If sumbit is clicked again without changed the text field the value should not change since strtotime should generate a proper and valid timestamp which strftime formats again.

Actual result:
--------------
Relative to today I type:

friday at 7pm

click submit and the value of the text box is now:
Friday, June 24 2005 at 05:00:00 PM

I don't type or change anything. Simply click submit again:
Friday, June 24 2005 at 03:00:00 PM

Every time I click submit the timestamp looses 2 hours.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-24 00:48 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-06-24 00:55 UTC] serge at skycomp dot ca
This server does not run php5.  It's on php4
 [2005-06-24 00:58 UTC] tony2001@php.net
Right. And I didn't ask you to upgrade the server. I asked to to try the latest snapshot.
And I'd really appreciate if you provide a reproduce code without HTML/forms/etc. Just a plain, short and clean PHP code that demonstrates the problem.
Thanks in advance.
 [2005-06-24 01:10 UTC] serge at skycomp dot ca
Ok I'll see about testing it agains the latest CVS if I have a chance.

A 100% php example is as follows:

<?
$timestr="Friday at 7pm";
print "Starting Value: '$timestr'\n";

for( $x=1; $x<=10; $x++) {
        $timestr=strftime('%A, %B %e %Y at %r',strtotime($timestr));
        print "The string is now: '$timestr'\n";
}
?>
 [2005-06-25 02:20 UTC] nickj-phpbugs at nickj dot org
Results of testing on PHP-5.1-dev CVS (php5-200506222230), with various format strings:
==============================================================
<?php
$formats = array (           // CHANGE : RESULT ON PHP-5.1-DEV
        '%A, %B %e %Y at %r',// original: +1 week +12 hours
        '%A %B %e %Y at %r', // remove comma: +1 week +12 hours
        '%A %B %e %Y %r',    // remove 'at': +1 week -2 hours
        '%r %A %B %e %Y',    // move %r to front: +1 week
        '%r %B %e %Y'        // remove the '%A' (day): -2 hours
                 );

foreach ($formats as $format) {
  print "-------- $format -----------\n";
  $timestr="Friday at 7pm";
  print "Starting Value: '$timestr'\n";

  for($x=1; $x<=10; $x++) {
    $tStamp = strtotime($timestr);
    $timestr=strftime($format,$tStamp);
    print "x: $x; timestr: '$timestr'; tStamp: $tStamp\n";
  }
}
?>
 [2005-06-25 03:07 UTC] nickj-phpbugs at nickj dot org
Some corrections, updates, relevant information, and then questions for PHP-5.1-dev:
=================================================================
Correction - This line:
        '%r %B %e %Y',       // remove the '%A' (day): -2 hours
Should say this instead:
        '%r %B %e %Y',       // remove the '%A' (day): -14 hours
=================================================================
Using this format string on PHP-5.1-dev leads to no change:
        '%r %B %e %Y %z'     // Add the timezone: No change.
=================================================================
Please see this comment at http://php.net/strftime about why 'at' cannot be used:

The description of strtotime says that it can "Parse about any English textual datetime description into a UNIX timestamp". Be careful, however,  when using "plain English". I was puzzled over why strtotime("June 23, 2003 at 12:00PM") returned a timestamp corresponding to 9:00 AM Central Time, until I realized the "at" was being interpreted as Azores Time or GMT+002. Writing strtotime("June 23, 2003 12:00PM") returned the correct timestamp.
=================================================================
Also I think Derick Rethans has recently checked in the new strtotime() implementation in PHP-5.1-dev, so may get different results between 5.1-dev and PHP4.
=================================================================
So the only unresolved questions I have for strtotime() in PHP-5.1-dev are whether these 3 formats should work:

- '%A %B %e %Y %r'
  e.g.: 'Friday July  1 2005 10:00:00 AM'
  shouldn't the weekday be assumed to be part of the format string, rather than a modifier?
  shouldn't the current timezone be assumed, rather than GMT?

- '%r %A %B %e %Y'
  e.g. '10:00:00 AM Friday July  1 2005'
  shouldn't the weekday be assumed to be part of the format string, rather than a modifier?
  shouldn't the current timezone be assumed, rather than GMT?

- '%r %B %e %Y'
  e.g. '10:00:00 AM July  1 2005'
  shouldn't the current timezone be assumed, rather than GMT?
 [2005-06-30 10:37 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

No bug here, "AT" is used as timezone abbreviation.

(Nick, please do not add non-related issues to the same bugreport but open a new one if you think there is a bug).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 12:01:32 2025 UTC