CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
DateTime / changing start of week

 



bgeus
New User

May 10, 2010, 5:11 AM

Post #1 of 7 (3232 views)
DateTime / changing start of week Can't Post

I'm using DateTime to truncate to the start day of the week (and other things) using timezone Europe/Amsterdam.

However, I got the request to use Sunday as the start of week instead of Monday.
I can't find anything in the documentation about this other than some printing options which aren't really helping me.
Also, local_day_of_week gives 1 on Sunday, but this is still not enough.

Does anybody have an idea if the start day of the week is changeable?


Bianca
User

Jun 7, 2010, 4:54 AM

Post #2 of 7 (3087 views)
Re: [bgeus] DateTime / changing start of week [In reply to] Can't Post

Hi bgeus,
I dont understand the problem.
Why do you not change your if then else statements in your script?


bgeus
New User

Jun 7, 2010, 5:24 AM

Post #3 of 7 (3085 views)
Re: [Bianca] DateTime / changing start of week [In reply to] Can't Post

Sorry guess I was a bit vague :)

The problem is that the week numbers change when the start of the week is changed. E.g. if Monday is the first day in week 10, then the Sunday before would be in week 9.
However, if Sunday is the first day of the week, that same Sunday would be in week 10 instead of 9.

So I want to be able to use DateTime to say my date is that Sunday, truncate to week and when I ask the date, get the starting day of week 10 (that Sunday), instead of 9 (Monday week ago).

Hope that makes more sense :)
I know there is a way around it, but was wondering if it was possible with a package that deals with dates already.


Bianca
User

Jun 7, 2010, 5:32 AM

Post #4 of 7 (3083 views)
Re: [bgeus] DateTime / changing start of week [In reply to] Can't Post

yes I understand.
Please look here: http://perltraining.com.au/tips/2009-02-26.html

strftime with %U

Quote
%U
The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %W.


Perhaps this helps?
I found it with search string "perl posix us-week" in google.


(This post was edited by Bianca on Jun 7, 2010, 5:34 AM)


bgeus
New User

Jun 7, 2010, 5:46 AM

Post #5 of 7 (3079 views)
Re: [Bianca] DateTime / changing start of week [In reply to] Can't Post

I can print the week number that starts on Sunday with DateTime as well, but that doesn't solve my problem.
I need to be able to truncate it to the start of the week so I can get a timestamp. Printing the current week only gets me so far :)

Sure, I can do it manually, but I wondered if DateTime could do that for me, because I have quite a bit of code to change that uses the truncate function.


Bianca
User

Jun 7, 2010, 7:26 AM

Post #6 of 7 (3073 views)
Re: [bgeus] DateTime / changing start of week [In reply to] Can't Post

Quote of Date::Calc's Doc:

Quote
Consistent with this practice, current norms and standards (such as
ISO/R 2015-1971, DIN 1355 and ISO 8601) define the Monday as the first
day of the week.

Perhaps it's not ordinary to take sunday as first day of week? Wink


bgeus
New User

Jun 7, 2010, 7:54 AM

Post #7 of 7 (3068 views)
Re: [Bianca] DateTime / changing start of week [In reply to] Can't Post

Hehe I made that argument, but try explaining that to the people here Tongue A lot of calendars have Sunday as the start of the week here (apparently Jesus was resurrected on a Sunday).

Anyway thanks for the effort, I gave up a while ago and made some functions to deal with it, just hoped I missed something.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives