in reply to How to get last month date period
As this is mostly static info (except for leap years), you might just want to use a simple lookup table.
my %period = ( Jan => ['01 Dec','31 Dec'], Feb => ['01 Jan','31 Jan'], Mar => ['01 Feb','28 Feb'], #... Dec => ['01 Nov','30 Nov'], ); my $curr_month = "Mar"; my $curr_year = 2010; my $p = $period{$curr_month}; print "$p->[0] $curr_year - $p->[1] $curr_year\n"; # 01 Feb 2010 - 2 +8 Feb 2010
To figure out when the "28 Feb" isn't correct, you could use one of the many date modules on CPAN (this is left as an exercise for... :). Or simply hardcode a list of those years up until the time you'll retire ;)
Update: the following should also work for up to 2099
... my $p = $period{$curr_month}; if ($curr_month eq "Mar") { $p->[1] = '29 Feb' unless $curr_year % 4; } ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get last month date period
by bart (Canon) on Mar 04, 2010 at 16:51 UTC | |
by almut (Canon) on Mar 04, 2010 at 16:56 UTC | |
|
Re^2: How to get last month date period
by roborat (Novice) on Mar 04, 2010 at 16:28 UTC |