use warnings; use strict; use DateTime; use DateTime::Format::Human::Duration; my $now = DateTime->new( time_zone => "UTC", year => 2019, month => 6, day => 10 ); my $fmt = DateTime::Format::Human::Duration->new(); for my $mon ( 4, 6, 8 ) { for my $day ( 1, 9 , 10, 11, 19 ) { my $date = DateTime->new( time_zone => "UTC", year => 2019, month => $mon, day => $day ); my $delta = $now->delta_md($date); my ($months,$days) = $delta->in_units(qw/ months days /); print $now->ymd, " to ", $date->ymd, " is ", $fmt->format_duration($delta, units=>[qw/months days/]); if ( $date>$now && ( $months>2 || $months==2 && $days>0 ) ) { print " *** Alert ***"; } print "\n"; } } __END__ 2019-06-10 to 2019-04-01 is 2 months and 9 days 2019-06-10 to 2019-04-09 is 2 months and 1 day 2019-06-10 to 2019-04-10 is 2 months 2019-06-10 to 2019-04-11 is 1 month and 29 days 2019-06-10 to 2019-04-19 is 1 month and 21 days 2019-06-10 to 2019-06-01 is 9 days 2019-06-10 to 2019-06-09 is 1 day 2019-06-10 to 2019-06-10 is no time 2019-06-10 to 2019-06-11 is 1 day 2019-06-10 to 2019-06-19 is 9 days 2019-06-10 to 2019-08-01 is 1 month and 21 days 2019-06-10 to 2019-08-09 is 1 month and 29 days 2019-06-10 to 2019-08-10 is 2 months 2019-06-10 to 2019-08-11 is 2 months and 1 day *** Alert *** 2019-06-10 to 2019-08-19 is 2 months and 9 days *** Alert ***