Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: How to calculate if today is before May 1

by ikegami (Patriarch)
on Dec 28, 2019 at 23:46 UTC ( [id://11110717]=note: print w/replies, xml ) Need Help??


in reply to Re: How to calculate if today is before May 1
in thread How to calculate if today is before May 1

At 2020-04-30T23:00:00 my local time, it will be considered May 1st by your approach.

To use local time (or some other time zone), you can use the following approach:

use DateTime qw( ); ( my $now = DateTime->now( time_zone => 'local' ) ) ->set_time_zone('floating'); my $cutoff_date = DateTime->new( year => $now->year, month => 5, day => 1, time_zone => 'floating', ); if ($now < $cutoff_date) { # do stuff }

The floating tz is used instead of local since some time zones have days don't have a midnight.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11110717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-03-28 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found