in reply to Re: Is there an easy way to get the start date of the current week?
in thread Is there an easy way to get the start date of the current week?

is there a reason you don't just subtract the right number of days from your start date to get the beginning of the week?

Care to demonstrate that given an arbitrary date?

  • Comment on Re^2: Is there an easy way to get the start date of the current week?

Replies are listed 'Best First'.
Re^3: Is there an easy way to get the start date of the current week?
by james2vegas (Chaplain) on Aug 21, 2010 at 14:34 UTC
    Sure.
    Update: changed hour to noon, instead of midnight, thanks daylight saving time (now works for the week of March 14 2010, thanks ikegami)
    use strict; use warnings; use Time::Piece; use Time::Seconds; use Date::Calc qw(Mktime); sub get_bofw { my $time = Mktime ( @_ ); my $t = localtime($time); my $bow = $t - ($t->_wday * ONE_DAY); } my $bofw = get_bofw( 2010, 03, 16, 12, 0, 0 ); print "$bofw\n";

      Ah! Okay, so finding, installing and working out how to use 3000 lines/95k of code is: "just subtracting the right number of days". Gotcha.

        Time::Seconds and Time::Piece are core modules, they do not need to be installed, and Date::Calc, already mentioned in this thread, is used to calculate the arbitrary date. But sure, how about this, then?

        Update: changed hour to noon, instead of midnight, thanks daylight saving time (now works for the week of March 14 2010, thanks ikegami)
        Update: Adding Time::Local, to make the call a little more clear: