Date('W') vs strftime('%W')

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have stumbled across what I think seems to be a weird situation, and
was hoping that maybe someone out there could point me in the
direction as to why it is occuring.

$date = '2008-09-16';

//- Outputs 38
echo date('W',strtotime($date));

//- Outputs 37
echo strftime('%W',strtotime($date));

This is a bit of a headache when trying to subtotal reports that are
based on a week of the year and Smarty date_format relies on strftime
while I am using date() earlier. I am unsure as to which one is
correct as I havent counted the weeks in the year to find out.. Which
should I use?

Re: Date('W') vs strftime('%W')

Turns out that date() is correct by my diary. So I will use that but
its still puzzling me as to why strftime is incorrect on this.

Quoted text here. Click to load it

Re: Date('W') vs strftime('%W')

kaydubbleu wrote:
Quoted text here. Click to load it

The date() function seems to count the first week from 1, while
strftime counts the first week from 0.


Re: Date('W') vs strftime('%W')

kaydubbleu escribió:
Quoted text here. Click to load it

They are different things:

W - ISO-8601 week number of year, weeks starting on Monday

%W - week number of the current year as a decimal number, starting with
the first Monday as the first day of the first week

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor al baño María:

Re: Date('W') vs strftime('%W')

contained the following:

Quoted text here. Click to load it

They may well be different, but it's not obvious.   I'd never have
expected there to be a 'Week 0'
Geoff Berrow  0110001001101100010000000110
100110001101101111001011100111010101101011 -

Re: Date('W') vs strftime('%W')

Geoff Berrow skrev:

Quoted text here. Click to load it

I think the difference is, that an ISO week belongs to the year, where
it has the most of it's days.
This implies, that week number one is the week with the first Thursday
of the year.



Re: Date('W') vs strftime('%W')

.oO(Jonathan Stein)

Quoted text here. Click to load it

Exactly. As a result there can be years with 53 weeks, because the first
week of the new year may already start in the december of the last year.


Site Timeline