472,353 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 7605
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 ?...
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...
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))) || '-' ||...
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...
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...
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 =...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.