php - Can someone explain how date("YW", strtotime("2016-01-02")); returns “201653”? -


date("yw", strtotime("2016-01-02")); returns “201653” 

year ok
week 2015

php iso-8601 compliant dates:

the purpose of standard provide unambiguous , well-defined method of representing dates , times, avoid misinterpretation of numeric representations of dates , times, particularly when data transferred between countries different conventions writing numeric dates , times.

this means first week of year defined as:

the week year's first thursday in

if 1 january on monday, tuesday, wednesday or thursday, in week 01. if 1 january on friday, saturday or sunday, in week 52 or 53 of previous year (there no week 00).

this means january 2nd of 2016 not in week 1 of 2016 far php concerned.

if use o flag date() iso-8601 year wilol return 2015:

echo date("ow", strtotime("2016-01-02")); // outputs: 201553 

demo

one way may want consider checking if month january , week number 53 first week of new calendar year (not iso-8601 year).

if (date('n') == 1 && date('w') == 53) {     // first calendar week of year } 

demo


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -