php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77502 strftime gets year wrong
Submitted: 2019-01-22 18:53 UTC Modified: 2019-01-22 19:18 UTC
From: tomstiller at alumni dot purdue dot edu Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.3.1 OS: Mac OS 10.14.2 (18C54)
Private report: No CVE-ID: None
 [2019-01-22 18:53 UTC] tomstiller at alumni dot purdue dot edu
Description:
------------
strftime returns the wrong year for the last day of certain years (2014 & 2018 tested.

Test script:
---------------
<?php
echo strftime("%c - %Z", strtotime('12/31/2014')), "\n";
echo strftime("%A, %B %e, %G - %Z", strtotime('12/31/2014')), "\n";

echo strftime("%c - %Z", strtotime('12/31/2018')), "\n";
echo strftime("%A, %B %e, %G - %Z", strtotime('12/31/2018')), "\n";
?>

Expected result:
----------------
Wed Dec 31 00:00:00 2014 - EST
Wednesday, December 31, 2014 - EST
Mon Dec 31 00:00:00 2018 - EST
Monday, December 31, 2018 - EST


Actual result:
--------------
Wed Dec 31 00:00:00 2014 - EST
Wednesday, December 31, 2015 - EST
Mon Dec 31 00:00:00 2018 - EST
Monday, December 31, 2019 - EST


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-22 19:18 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2019-01-22 19:18 UTC] derick@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.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This is correct behaviour. %G returns the *ISO* 8601 week based year, and not the natural year, which is %Y. See also: https://derickrethans.nl/iso-8601-weeks.html
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC