Pergunta

I have this code

$week = date('W', strtotime("2013-12-30"));

and $week is returning 01

How can that return 01 if we are in December? How can I fix this? As this is impacting on another part of the code where I'm trying to get the monday of each week:

$monday = date("Y-m-d", strtotime("{$year}-W{$week}-1"));

But when I do that with that date, it's returning the monday of week 01.

Foi útil?

Solução 2

It is working correctly.

The "week number" is sometimes counterintuitive. See the note from "Jimmy" for the documentation of date using W format: http://www.php.net/manual/en/function.date.php#106974

Outras dicas

date("W") returns the iso8601 week number. That date falls into the first week of the next year. This can occur when the last day(s) of December fall mid-week. This can also happen when December ends late in the week. The first couple of days of January can be considered part of the previous year.

See Week dates in Wikipedia for a better explanation:

If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top