From: szr on
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


From: Peter J. Holzer on
On 2008-05-04 16:15, szr <szrRE(a)szromanMO.comVE> wrote:
> PerlFAQ Server wrote:
>> 4.17: How do I find yesterday's date?
[...]
>> 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?

Yes.

> E.G.,
> $ perl -e 'print scalar localtime(time - 86400), "\n";'

Consider:

% perl -le 'print scalar localtime(1206914460)'
Mon Mar 31 00:01:00 2008
% perl -le 'print scalar localtime(1206914460-86400)'
Sat Mar 29 23:01:00 2008

% perl -le 'print scalar localtime(1225061940)'
Sun Oct 26 23:59:00 2008
% perl -le 'print scalar localtime(1225061940-86400)'
Sun Oct 26 00:59:00 2008


> Or is it safe to use that?

Only after 01:00 and before 23:00.

hp
From: brian d foy on
In article <fvknfp026so(a)news4.newsguy.com>, szr <szrRE(a)szromanMO.comVE>
wrote:


> > 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?

Well, that last paragraph explains why that won't work. There are two
days where it breaks. On one you'll get the date from two days ago, and
the other the same day. So, no, it's not safe.
From: Andrew DeFaria on
brian d foy wrote:
> In article <fvknfp026so(a)news4.newsguy.com>, szr
> <szrRE(a)szromanMO.comVE> wrote:
>
>>> 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?
> Well, that last paragraph explains why that won't work. There are two
> days where it breaks. On one you'll get the date from two days ago,
> and the other the same day. So, no, it's not safe.
Actually no, you won't get a day 2 days ago or the same date unless
you're within a certain time of day. For example, if you are trying to
find out what day was before the DST changing day at say 5 Pm you'll
come up with the previous day @ 4 Pm, wouldn't you?

Besides - 86400 is reliable here! Here in Arizona that is! Wish you guys
would wise up and stop changing your clocks all the time. It's damn
annoying! ;-)
--
Andrew DeFaria <http://defaria.com>
Please, God, deliver us from your followers!