php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33532 Different output for strftime() and date()
Submitted: 2005-07-01 06:15 UTC Modified: 2005-07-03 21:15 UTC
From: nickj-phpbugs at nickj dot org Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5CVS-2005-07-01 (dev) OS: Debian Woody GNU/Linux 3.0r6
Private report: No CVE-ID: None
 [2005-07-01 06:15 UTC] nickj-phpbugs at nickj dot org
Description:
------------
Getting different output for strftime() and date(), and wondering whether these should be the same.

Example code:

<?php

print "TZ has NOT been set\n";
print "Should strftime==datestr? Strftime seems to assume GMT tStamp.\n";
$input = "10:00:00 AM July 1 2005";
print "input    " . $input . "\n";
$tStamp = strtotime($input);
print "strftime " . strftime("%r %B%e %Y", $tStamp) . "\n";
print "datestr  " . date ("H:i:s A F j Y", $tStamp) . "\n";

print "\nSetting TZ\n";
putenv ("TZ=Australia/Sydney");
$input = "10:00:00 AM July 1 2005";
print "input    " . $input . "\n";
$tStamp = strtotime($input);
print "strftime " . strftime("%r %B%e %Y", $tStamp) . "\n";
print "datestr  " . date ("H:i:s A F j Y", $tStamp) . "\n";

?>

Output:
-------------------------------------------------
ludo:~/tmp/php-5.1-dev/strftime-vs-date# ../php5-200507010030/sapi/cli/php ./strftime-vs-date.php 
TZ has NOT been set
Should strftime==datestr? Strftime seems to assume GMT tStamp.
input    10:00:00 AM July 1 2005
strftime 08:00:00 PM July 1 2005
datestr  10:00:00 AM July 1 2005

Setting TZ
input    10:00:00 AM July 1 2005
strftime 10:00:00 AM July 1 2005
datestr  10:00:00 AM July 1 2005
ludo:~/tmp/php-5.1-dev/strftime-vs-date# 
-------------------------------------------------

Expected output:
-------------------------------------------------
TZ has NOT been set
Should strftime==datestr? Strftime seems to assume GMT tStamp.
input    10:00:00 AM July 1 2005
strftime 10:00:00 AM July 1 2005
datestr  10:00:00 AM July 1 2005

Setting TZ
input    10:00:00 AM July 1 2005
strftime 10:00:00 AM July 1 2005
datestr  10:00:00 AM July 1 2005
ludo:~/tmp/php-5.1-dev/strftime-vs-date# 
-------------------------------------------------

Note: the "%r" strftime format is described thus: "time in a.m. and p.m. notation". The strftime documentation does not indicate that this is altered by the locale settings (unlike the weekday, month, and so on are). However my locale is English anyway, which is what date() seems to use, and the locale is not adjusted by the above script, so I would anticipate getting the same output between date and strftime.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-01 09:38 UTC] sniper@php.net
Derick was working on a new *date() implementation too..
 [2005-07-01 10:15 UTC] derick@php.net
Yeha, but this is a strftime() problem, not a date() problem ;-)
 [2005-07-03 21:15 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Should be fixed in CVS now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC