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