php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21212 strftime fails when crossing year
Submitted: 2002-12-27 08:22 UTC Modified: 2002-12-30 12:45 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: o dot oudry at voila dot fr Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.2.3 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: o dot oudry at voila dot fr
New email:
PHP Version: OS:

 

 [2002-12-27 08:22 UTC] o dot oudry at voila dot fr
/* function strftime produce wrong result with a timestamp close to the end of
   Year,the four digit year value is sometimes 1 year after (see "30/12/2002")
   and sometimes 1 year before (see "01/01/2005") the good one.
   hope this help
*/


$dateTab=array();
$dateTab[0]  = "Dec 29 2001";
$dateTab[1]  = "Dec 30 2001";
$dateTab[2]  = "Dec 31 2001"; wrong output with strftime
$dateTab[3]  = "Jan 01 2002";
$dateTab[4]  = "Dec 29 2002";
$dateTab[5]  = "Dec 30 2002"; wrong output with strftime
$dateTab[6]  = "Dec 31 2002"; wrong output with strftime
$dateTab[7]  = "Jan 01 2003";
$dateTab[8]  = "Dec 28 2003"; 
$dateTab[9]  = "Dec 29 2003"; wrong output with strftime
$dateTab[10] = "Dec 30 2003"; wrong output with strftime
$dateTab[11] = "Dec 31 2003"; wrong output with strftime
$dateTab[12] = "Jan 01 2004";
$dateTab[13] = "Dec 28 2004";
$dateTab[14] = "Dec 29 2004";
$dateTab[15] = "Dec 30 2004";
$dateTab[16] = "Dec 31 2004";
$dateTab[17] = "Jan 01 2005"; wrong output with strftime
$dateTab[18] = "Jan 02 2005"; wrong output with strftime
$dateTab[19] = "Jan 03 2005";
$dateTab[20] = "Jan 04 2005";
$dateTab[21] = "Jan 05 2005";

foreach($dateTab as $currentDate) {
    if (($timestamp = strtotime($currentDate)) === -1)
    {
        echo "The string ($currentDate) is bogus";
    } 
    else
    {
         $result[0] =  date('d/m/Y',$timestamp);
         $result[1] = strftime("%d/%m/%G",$timestamp);
        
         if($result[1] == $result[0]) {
            echo "$currentDate == $result[0] == $result[1]<br>"; 
         }
         else
         {
            echo "$currentDate == $result[0] != <font color=red>$result[1]</font><br>"; 
         }
    }         
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-30 04:04 UTC] o dot oudry at voila dot fr
-
 [2002-12-30 12:45 UTC] pollita@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Please note the manual page: http://www.php.net/manual/en/function.strftime.php

----------------------------
%G - The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead. 

----------------------------

A reminder about ISO week numbers.  They begin on mondays, end on sundays, and are considered a part of the year in which the majority of their days fall.

12/31/2001 falls on a monday, it's ISO week ends on Sunday 1/6/2002, (six days fall in 2002, one falls in 2001) ergo %G for that date returns "2002".  

This is expected behavior for %G.  Try using %Y instead. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC