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: Frequently Asked Questions:
How do I find the week-of-the-year/day-of-the-year

 



Jasmine
Administrator

Jan 19, 2001, 2:38 PM

Post #1 of 1 (1661 views)
How do I find the week-of-the-year/day-of-the-year Can't Post

(From the Perl FAQ)

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

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

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

or more legibly (in 5.004 or higher):

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

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

Code
    $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.



 
 


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

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