in reply to About this week Date
#!/usr/bin/perl use strict; use warnings; sub this_monday_thru_friday { my ($now,$wday,$mon_secs,$fri_secs,@mth,@mon,@fri); $now = time(); $wday = (localtime($now))[6]; $mon_secs = ( 1 - $wday ) * 60 * 60 * 24 + $now; $fri_secs = ( 5 - $wday ) * 60 * 60 * 24 + $now; @mth = qw( January February March April May June July August September October November December ); @mon = (localtime($mon_secs))[3..5]; # mday,month,year @fri = (localtime($fri_secs))[3..5]; # mday,month,year $mon[2] += 1900; # change monday year to four digits $fri[2] += 1900; # ... do the same for this friday return $mth[$mon[1]],@mon[0,2],$mth[$fri[1]],@fri[0,2]; } # Example output: August 24 2009 August 28 2009 printf "%s\n", join " ", this_monday_thru_friday();
|
|---|