473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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?
Oct 10 '08 #1
6 7660
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...@gmail.comwrote:
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?
Oct 10 '08 #2
kaydubbleu wrote:
On Oct 10, 10:36 am, kaydubbleu <kevwilli...@gmail.comwrote:
>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
Oct 10 '08 #3
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
--
Oct 10 '08 #4
Message-ID: <gc**********@huron.algomas.orgfrom Á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
Oct 10 '08 #5
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
Oct 10 '08 #6
..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
Oct 10 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
3
by: Peter Moscatt | last post by:
I am wanting to return the system date using the following: date.today() How would I then convert this to a string ? Pete
3
by: Matt | last post by:
Given a date, how to find the beginning date and ending date of that week please advise!
5
by: Greg Scharlemann | last post by:
If I have a date that looks like: 2005-12-07 10:10:00 How could I manipulate it in php to say "Dec, 07, 2005"? I can separate the string at the space, but don't know where to go from...
11
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' ||...
5
by: Des | last post by:
I have to do an events calender for a church. The events display will be limited to that week. If someone went in today Wed 24th I want to display 21st to 27th. I dont want any code samples, just...
9
by: Bob Sanderson | last post by:
I have a field in a database called DateRcvd. At present, it outputs in my report in the yyyy-mm-dd format. I would like it to display in the dd/mm/yy format. What is the easiest way to accomplish...
3
by: HSeganfredo | last post by:
Folks, my code below truncates the output as: chars 0,200709 chars 0,1839 If I change to: i = strftime(date, 9, "%Y%m%d", brokentime); j = strftime(hour, 7, "%H%M%S", brokentime); it...
5
by: Amzul | last post by:
hello all i am breaking my head over this and there isnt any good solution that i have saw til now, my problam is that i want to tell the date of a sertin day what was choosen <select...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.