php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43849 date('YW', strtotime('2007-12-31')) return 200701
Submitted: 2008-01-15 06:18 UTC Modified: 2008-01-15 07:12 UTC
From: kiange at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.5 OS: Ubuntu
Private report: No CVE-ID: None
 [2008-01-15 06:18 UTC] kiange at gmail dot com
Description:
------------
Enviornments:
PHP 5.2.3-1ubuntu6.2

Reproduce code:
---------------
echo date('YW', strtotime('2007-12-31'));
// return 200701, maybe 200801 according to the reference page
echo strftime("%Y%W",strtotime("2007-12-31"));
// return 200753

Expected result:
----------------
200753 or 200801

Actual result:
--------------
200701

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-15 07:12 UTC] derick@php.net
This is correct, the "W" shows the ISO week, which you need to match against the ISO year specifier ("o" - small "O"). ISO Week 2008-01 goes from Dec 31st to Jan 6th. This will return what you expect:

echo date('Yo', strtotime('2007-12-31')), "\n";

strftime() would not be good to rely on, as the output might differ on other operating systems.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC