in reply to How to calculate if today is before May 1

The DateTime distribution can help you:

use warnings; use strict; use DateTime; my ($month, $day) = (5, 1); my $now = DateTime->now; my $year = $now->year; my $known_date = DateTime->new( year => $year, month => $month, day => $day, ); if ($now < $known_date) { # do stuff }

Replies are listed 'Best First'.
Re^2: How to calculate if today is before May 1
by ikegami (Patriarch) on Dec 28, 2019 at 23:46 UTC

    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.