use Date::Calc qw(Today Add_Delta_Days); $yesterday=sprintf( "%04d/%02d/%02d", Add_Delta_Days( Today(), -1 ) ); print $yesterday
>>> 2008/12/03 Bour9 > -----Message d'origine----- > De : [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] De la > part de Bill Luebkert > Envoyé : jeudi 4 décembre 2008 00:49 > À : activeperl@listserv.activestate.com > Objet : Re: How to get yesterday's date in Perl > > [EMAIL PROTECTED] wrote: > >> This occurs on the 23th hour in the fall and the 0th hour > in the spring. > > This program shows a brute force way > >> to find these that might convince you [1]. > > > > > > Slick! I'm convinced. Hmm, so if you need it to be ever > accurate (and want > > to stay w/ localtime() you need to track changes in the DST field, > > something like: > > my ($isdst) = ( localtime() ) [8]; > > > > my ($mday, $mon, $year, $prev_isdst) = (localtime(time - > 60 * 60 * 24) )[ > > 3,4,5, 8]; > > printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, > > $isdst == $prev_isdst ? $mday > > : $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3] > > : (localtime($t - 60 * 60 * 25) )[ 3] > > ); > > > > If he's only interested in the date and not the time, I would think > just using localtime and changing the hour field to noon and using > Time::Local::timelocal to reverse back to epoch time would ensure > that your next localtime call would produce the correct date no > matter what the time is. > > use Time::Local; > my @t = localtime; # convert epoch time for today to fields > $t[2] = 12; # change hour to noonish > my $time = timelocal (@t); # convert back to epoch time > my @d = localtime $time; # @d now has the correct date > for yesterday > # which you could also use with > POSIX::strftime > # to format as you like > _______________________________________________ > ActivePerl mailing list > ActivePerl@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs