in reply to Re^2: 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?

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";
  • Comment on Re^3: Is there an easy way to get the start date of the current week?
  • Download Code

Replies are listed 'Best First'.
Re^4: Is there an easy way to get the start date of the current week?
by BrowserUk (Patriarch) on Aug 21, 2010 at 15:01 UTC

    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:

        The numbers are for Date::Calc on its own. You didn't appear to be using Time Piece or Time::Seconds, so I didn't count them.