in reply to Get date interval from week of year -> Date::Manip

use DateTime; my $now = DateTime->now; my $week = $now->week_number; print $now->ymd," now (week $week)\n"; my $first = DateTime->new( year => $now->week_year, month => 1, day => 1, ); print $first->ymd," beginning of the year \n";; $first->add( weeks => $now->week_number ); print $first->ymd, " beginning of week $week\n"; $first->add( weeks => 1 ); print $first->ymd, " end of week $week\n"; __END__ 2003-09-08 now (week 37) 2003-01-01 beginning of the year 2003-09-17 beginning of week 37 2003-09-24 end of week 37

Replies are listed 'Best First'.
Re: Re: Get date interval from week of year -> Date::Manip
by PodMaster (Abbot) on Sep 08, 2003 at 08:18 UTC
    I'm glad to see others using DateTime, but that's not quite right. January 1st is not neccessarily the beginning of the week, I modified your snippet like so update: aren't I funny {grin} every year has 52 weeks ($last->week_number, lol).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Get date interval from week of year -> Date::Manip
by Abigail-II (Bishop) on Sep 08, 2003 at 07:43 UTC
    2003-09-08 now (week 37) 2003-01-01 beginning of the year 2003-09-17 beginning of week 37 2003-09-24 end of week 37

    Well, it's nice that people test their code before posting it, but if you don't look at the output then what's the point? According to your program, Sep 8 is between Sep 17 and Sep 24.

    Abigail

      How do you draw that conclusion? (nowhere do I say that Sept8 is between Sept17 and Sept24). It's like you're purposefuly being rude ;(
        How do you draw that conclusion? (nowhere do I say that Sept8 is between Sept17 and Sept24).
        Ok, let me spell it out for you.
        2003-09-17 beginning of week 37

        Week 37 starts on September 17.

        2003-09-24 end of week 37

        And week 37 ends on September 24 (making it an 8 day week...)

        2003-09-08 now (week 37)

        8 September is in week 37. To be in a week, you must be on or after the start of the week, and on or before the end of the week. Conclusion, 8 September has to be between 17 and 24 September.

        Abigail

        elementary my dear anon.

        line one states that now 2003-09-08 is week 37.
        line 3 states that 2003-09-17 is the beginning of week 37
        line 4 states that 2003-09-24 is end of week 37

        ergo week 37 contains at least 2003-09-08 thru 2003-09-24.
        something in the neighborhood of 17 days.

        Abigail, perhaps you were a tad hasty, nowhere does he state that the eighth falls between the seventeenth and the twenty fourth in his seventeen day week.

        However, I do have difficulty understanding how a 17 day week can have the 17th and the 8th in the beginning,since the 17th is the 10th day of the 17 day week, that is over half way through the week and is no longer the beginning.

        Wait, Wait, It was never stated that the 24th was the LAST day of the week, it could contain more days, so both the 8th and the 17th COULD be in the beginning of the week, AND the 8th would not have to fall between the 17th and the 24th. Also proving my earlier statement incorrect (nope, no seventeen day week claimed here0.

        My apologies to Anon. This is not a flame, but the logic does appeal to my twisted sense of humor.

        I only hope your reply will extend the number of days in the week rather than a mundane code correction.

        Enjoy!
        dageek

        p.s. Please forgive the use of the male gender, since I do not know the true gender of Anon, but this seems to be the kind of mistake a guy like me would make.