in reply to About this week Date
This task has two parts: one is to find the first and last day of the current week, the other is to print the interval as a human-readable format. For the first, we'll use the Date::Manip::Date_GetPrev function which does the right thing. I have to hand-roll the second one.
Here's my solution. This assumes your dates start with Monday.
#!perl + use warnings; use strict; + use Date::Manip; my $mon = Date_GetPrev("now", "monday", 1, 8); my $fri = DateCalc($mon, "+4days"); my($mony, $monm) = UnixDate($mon, "%y", "%m"); my($friy, $frim) = UnixDate($fri, "%y", "%m"); my $r; if ($monm == $frim) { $r = UnixDate($mon, "%B %e-") . UnixDate($fri, "%e, %Y\n") } elsif ($mony == $friy) { $r = UnixDate($mon, "%B %e-") . UnixDate($fri, "%B %e, %Y\n") } else { $r = die "homework for the reader"; } print $r; __END__
|
|---|