renpai has asked for the wisdom of the Perl Monks concerning the following question:

I want to generate a report for last month and i want to generate in a loop where eg yesterdat date...$timestr=time2str ("%Y%m%d",time-86400); so that when i run the program it should a report for last 30 or 31 days depends on the number of days in a month
  • Comment on How to generate a report for last month

Replies are listed 'Best First'.
Re: How to generate a report for last month
by Brovnik (Hermit) on Jun 01, 2001 at 14:31 UTC
    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.
      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
Re: How to generate a report for last month
by Beatnik (Parson) on Jun 03, 2001 at 01:43 UTC
    As a sidenote: HTML::CalendarMonth & PlotCalendar look nice enough for monthly overviews...

    I thought that R in Perl stood for Regenerate... Report, who got THAT idea?? </Sarcasm>

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.