in reply to How to generate a report for last month

Here are a couple of ways, using Class::Date]
sub dayslastmonth { use Class::Date qw(date now); my $date = now; my $first = new Class::Date {year=>$date->year, month=>$date->month +, day=>1}; my $last = $first - '0-0-1'; return $last->day; }
and Date::Calc
sub dayslastmonth { use Date::Calc qw(Today Days_in_Month); my ($year, $month, $day) = Today(); return Days_in_Month($year,$month - 1); }
Class::Date is more object-oriented, but both have similar functionality.

Replies are listed 'Best First'.
Re: Re: How to generate a report for last month
by buckaduck (Chaplain) on Jun 01, 2001 at 23:01 UTC
    use Date::Calc qw(Today Days_in_Month); my ($year, $month, $day) = Today(); return Days_in_Month($year,$month - 1);
    That's not going to work in January. You should also import the Add_Delta_YMD function:
    sub dayslastmonth { use Date::Calc qw(Today Days_in_Month Add_Delta_YMD); my ($year,$month,$day) = Add_Delta_YMD(Today(), 0, -1, 0); return Days_in_Month($year,$month); }
    buckaduck