|
Posted by szr on May 4, 2008, 12:15 pm
Please log in for more thread options
PerlFAQ Server wrote:
> This is an excerpt from the latest version perlfaq4.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>
> --------------------------------------------------------------------
>
> 4.17: How do I find yesterday's date?
>
> (contributed by brian d foy)
>
> Use one of the Date modules. The "DateTime" module makes it
> simple, and give you the same time of day, only the day before.
>
> use DateTime;
>
> my $yesterday = DateTime->now->subtract( days => 1 );
>
> print "Yesterday was $yesterday\n";
>
> You can also use the "Date::Calc" module using its "Today_and_Now"
> function.
>
> use Date::Calc qw( Today_and_Now Add_Delta_DHMS );
>
> my @date_time = Add_Delta_DHMS( Today_and_Now(), -1, 0, 0,
> 0 );
>
> print "@date_time\n";
>
> Most people try to use the time rather than the calendar to figure
> out dates, but that assumes that days are twenty-four hours each.
> For most people, there are two days a year when they aren't: the
> switch to and from summer time throws this off. Let the modules do
> the work.
So according to the last part, that makes
time - 86400
unreliable?
E.G.,
$ perl -e 'print scalar localtime(time - 86400), "\n";'
Or is it safe to use that?
--
szr
|