Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

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

 
   Database Help (Home) -> PHP RSS
Next:  MDX Calculated Measure from Dimension Value?  
Author Message
kaydubbleu

External


Since: Oct 09, 2008
Posts: 2



(Msg. 1) Posted: Thu Oct 09, 2008 5:36 pm
Post subject: Date('W') vs strftime('%W')
Archived from groups: comp>lang>php (more info?)

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?

 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
kaydubbleu

External


Since: Oct 09, 2008
Posts: 2



(Msg. 2) Posted: Thu Oct 09, 2008 5:49 pm
Post subject: Re: Date('W') vs strftime('%W') [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

On Oct 10, 10:36 am, kaydubbleu <kevwilli... RemoveThis @gmail.com> wrote:
> 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?

 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
Curtis

External


Since: Aug 09, 2008
Posts: 46



(Msg. 3) Posted: Fri Oct 10, 2008 3:25 am
Post subject: Re: Date('W') vs strftime('%W') [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

kaydubbleu wrote:
> On Oct 10, 10:36 am, kaydubbleu <kevwilli....RemoveThis@gmail.com> wrote:
>> 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?
> 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.

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

--
Curtis
 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
Álvaro_G._Vicario

External


Since: Apr 11, 2008
Posts: 955



(Msg. 4) Posted: Fri Oct 10, 2008 4:25 am
Post subject: Re: Date('W') vs strftime('%W') [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

kaydubbleu escribió:
> $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?

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





--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
Geoff Berrow1

External


Since: Dec 24, 2003
Posts: 352



(Msg. 5) Posted: Fri Oct 10, 2008 5:25 am
Post subject: Re: Date('W') vs strftime('%W') [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Message-ID: <gcn0j5$jj5$1@huron.algomas.org> from Álvaro G. Vicario
contained the following:

>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

They may well be different, but it's not obvious. I'd never have
expected there to be a 'Week 0'
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
Jonathan Stein

External


Since: Oct 03, 2008
Posts: 4



(Msg. 6) Posted: Fri Oct 10, 2008 8:25 am
Post subject: Re: Date('W') vs strftime('%W') [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Geoff Berrow skrev:

>> 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
>
> They may well be different, but it's not obvious. I'd never have
> expected there to be a 'Week 0'

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.

Regards

Jonathan
 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
Michael Fesser

External


Since: Dec 17, 2007
Posts: 867



(Msg. 7) Posted: Fri Oct 10, 2008 2:25 pm
Post subject: Re: Date('W') vs strftime('%W') [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(Jonathan Stein)

>Geoff Berrow skrev:
>
>>> 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
>>
>> They may well be different, but it's not obvious. I'd never have
>> expected there to be a 'Week 0'
>
>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.

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.

Micha
 >> Stay informed about: Date('W') vs strftime('%W') 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]