# 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); }