php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79081 Issue with date('Y-W')
Submitted: 2020-01-08 13:47 UTC Modified: 2020-01-08 15:20 UTC
From: tomi at vipmail dot hu Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Windows
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: tomi at vipmail dot hu
New email:
PHP Version: OS:

 

 [2020-01-08 13:47 UTC] tomi at vipmail dot hu
Description:
------------
I think this is just a small bug. 

"W" use ISO-8601 standard and this is enable the following: W01 can start at last year. (Ex. 2020W01 = 2019-12-30 - 2020-01-05)

In this case when I want to get week number - with year information - based on the first day of the week, I get wrong year information.

I tested this with PHP 7.4.0. Everything comes from php.net without any special modules or extensions.

You can reproduce the issue with the "Test script".

Test script:
---------------
$date_string = '2020W01';

$from = date('Y-m-d', strtotime($date_string));
$to = date('Y-m-d', strtotime($date_string . '7'));

echo $from .' - '. $to .'<br/>';

$from = date('Y-W', strtotime($date_string));
$to = date('Y-W', strtotime($date_string .'7'));

echo $from .' - '. $to .'<br/>';

$from = date('Y-W', mktime(0,0,0,12,30,2019));

echo $from;

Expected result:
----------------
2019-12-30 - 2020-01-05
2020-01 - 2020-01
2020-01

Actual result:
--------------
2019-12-30 - 2020-01-05
2019-01 - 2020-01
2019-01

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-08 15:20 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-01-08 15:20 UTC] cmb@php.net
You have to use `o` instead of `Y` in combination with `W`, see
<https://3v4l.org/KXUXc> and
<https://www.php.net/manual/en/function.date.php#refsect1-function.date-parameters>.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC