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

The problem with basing it off week numbers is that week numbers are based on weeks starting on Monday, not Sunday, so you would need to check that your start date is not already a Sunday before continuing.

Is this purely an intellectual exercise or 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?
  • Comment on Re: Is there an easy way to get the start date of the current week?

Replies are listed 'Best First'.
Re^2: Is there an easy way to get the start date of the current week?
by BrowserUk (Patriarch) on Aug 21, 2010 at 14:16 UTC
    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?

      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.