in reply to There's More Than One Way To Do It

Since Sunday (or, if you like, Monday) is the beginning of the week, the "this week" asks for everything from that day to the present. So, just have some code figure out when the most recent $FirstDayOfWeek was. Date::Manip makes this easy, I bet it's easy with Date::Calc too. The former is kind of heavyweight for this task; the latter is definitely recommended for any serious mangling dates.

Just for fun, and much later than merlyn and davorg presented their (more elegant) versions, here's something from off the top of my head that uses no modules, is only barely tested, and is decidedly ugly (assumes Sunday is the date to fix on):

# returns the DD-MM-YYYY of the most recent Sunday sub last_sunday { my $from = shift; my $time = localtime($from); my $day_of_week = (split /\s/, $time)[0]; # if today is Sunday, then we just want stuff # since midnight return date_format($from) if $day_of_week eq 'Sun'; foreach my $i (1..7) { my $day_of_week_then = (split /\s/, localtime($from - $i * 86400))[0]; return date_format($from - $i *86400) if $day_of_week_then eq 'Sun'; } } sub date_format { my $timestamp = shift; my @times = localtime $timestamp; return sprintf("%02d-%02d-%4d", $times[3], $times[4]+1, $times +[5]+1900); }

HTH

Philosophy can be made out of anything. Or less -- Jerry A. Fodor