htmanning has asked for the wisdom of the Perl Monks concerning the following question:
But what I need now is to restrict future reservations to no more than 1 week ahead of time, but something like this doesn't work:use DateTime; my $now = DateTime->now( time_zone => 'Pacific/Honolulu' ); my $reservation_date = DateTime->new( year => $CONFIG{'date_year'}, month => $CONFIG{'date_month'}, day => $CONFIG{'date_day'}, hour => $myhour, minute => $mymin, time_zone => 'Pacific/Honolulu', ); if ($reservation_date < $now) { print "error"; }
It seems I have to use the duration compare class, but I'm not sure how to do it when I'm only comparing the reservation date to now, and the base time to compare to is now.} elsif ($reservation_date - $now > 7) { do something. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting days with DateTime (updated x2)
by haukex (Archbishop) on Apr 01, 2020 at 19:06 UTC | |
by tobyink (Canon) on Apr 02, 2020 at 07:18 UTC | |
by htmanning (Friar) on Apr 01, 2020 at 19:33 UTC | |
| |
|
Re: Counting days with DateTime
by Corion (Patriarch) on Apr 01, 2020 at 18:54 UTC | |
|
Re: Counting days with DateTime
by soonix (Chancellor) on Apr 02, 2020 at 08:36 UTC |