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

This is probably a dumb question but i want to get yesterdays date. This is my command: my $yesterday_date = localtime(time() - 60*60*24*1); that gives the date July 4. I want the date as July 04. is their a easy way to this? Thanks.

Replies are listed 'Best First'.
Re: Yesterday date
by Corion (Patriarch) on Jul 05, 2007 at 18:55 UTC
Re: Yesterday date
by FunkyMonk (Bishop) on Jul 05, 2007 at 19:02 UTC
    If I were restrained to just standard modules, I'd use strftime from the POSIX module to format time-24*60*60. If I wanted a quick hack, I'd use Date::Manip. Otherwise I'd use DateTime.

    update: added direct link to strftime. I didn't know you could do that. Thanks Corion.

Re: Yesterday date
by Joost (Canon) on Jul 05, 2007 at 19:02 UTC
Re: Yesterday date
by mojodaddy (Pilgrim) on Jul 06, 2007 at 02:22 UTC
    use Date::Simple qw(today); my $yesterday = today() - 1; print $yesterday->format("%B %d");
Re: Yesterday date
by MonkE (Hermit) on Jul 06, 2007 at 00:11 UTC

    One thing that leaps to mind when I see people doing date and time arithmetic is that ,sadly, not all days have 86400 seconds (24 hours). When dealing with local times, there are such things as 23 and 25 hour days. In Spring you'll get one 23 hour day during the standard-to-daylight-savings switch. In Autumn you'll get one 25 hour day during the DST-to-standard time switch.

    You should probably take Corion's advice and have a look at that node he recommended: How do i find yesterday's date. I thought it was pretty good.

Re: Yesterday date
by Anonymous Monk on Jul 06, 2007 at 00:56 UTC
    sprintf("%s %s %02d %s %s\n", split(/\s+/,scalar(localtime(time()-60*6 +0*24))));