Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Find 30 days from today's date

by frozenwithjoy (Priest)
on Jun 07, 2013 at 15:56 UTC ( #1037691=note: print w/replies, xml ) Need Help??

in reply to Find 30 days from today's date

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use DateTime; my $thirty_days_ago = DateTime->today->subtract(days => 30); say $thirty_days_ago; __END__ 2013-05-08T00:00:00

Replies are listed 'Best First'.
Re^2: Find 30 days from today's date
by ikegami (Pope) on Jun 09, 2013 at 06:05 UTC
    If he wants the date where his computer is located (as opposed to the date somewhere in Europe),
    my $thirty_days_ago = DateTime->today(time_zone => 'local')->subtract( +days => 30);

    Note that the above solution will fail two days a year in time zones with no midnight on a DST change. (There is at least one such time zone.) Workaround:

    my $thirty_days_ago = DateTime->now(time_zone => 'local')->set_hour(12 +)->subtract(days => 30);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037691]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-03-25 01:51 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (299 votes). Check out past polls.