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; } ...
In reply to Re: How to get last month date period
by almut
in thread How to get last month date period
by roborat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |