I'm trying to convert a {YYYY}W{WW} string with strftime as explained is this answer.
However it always gives W-1 :
echo $date = utf8_encode(strftime('%B %Y, week %W', strtotime('2015W38')));
// this will echo "September 2015, week 37"
// but should echo "September 2015, week 38"
How can I properly correct this ?
PHP Version : 5.6.9
strtotime:
ISO year with ISO week YY "-"? "W" W "2008W27", "2008-W28"
strftime:
%W A numeric representation of the week of the year, starting with the first Monday as the first week 46 (for the 46th week of the year beginning with a Monday)
%V ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week 01 through 53 (where 53 accounts for an overlapping week)
So probably you should use
echo $date = utf8_encode(strftime('%B %Y, week %V', strtotime('2015W38')));
Desclaimer: I am not proficient with php, so please do validate my thoughts.
EDIT>
As @syck adds: ISO 8601 counts weeks from 01 and the first week is the one with the year's first Thursday in it (see here).
This works as intended:
$year = "2015"; // Year 2015
$week = "38"; // Week 38
$date1 = date( "F Y, W", strtotime($year."W".$week) );
echo $date1;
//September 2015, 38
You have to replace %W with %V
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With