Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How do I find the week-of-the-year/day-of-the-year?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:20 UTC ( #585=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

The day of the year is in the array returned by localtime() (see localtime):

    $day_of_year = (localtime(time()))[7];

or more legibly (in 5.004 or higher):

    use Time::localtime;
    $day_of_year = localtime(time())->yday;

You can find the week of the year by dividing this by 7:

    $week_of_year = int($day_of_year / 7);

Of course, this believes that weeks start at zero. The Date::Calc module from CPAN has a lot of date calculation functions, including day of the year, week of the year, and so on. Note that not all business consider ``week 1'' to be the same; for example, American business often consider the first week with a Monday in it to be Work Week #1, despite ISO 8601, which consider WW1 to be the frist week with a Thursday in it.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[choroba]: Well, merging two hashes recursivelly is not that hard either, but...
[Corion]: choroba: Yeah - I think I used (and extended) Hash::Merge for recursive merging

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2018-02-23 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (309 votes). Check out past polls.

    Notices?