in reply to Counting days with DateTime
Personally I try to avoid the overloaded DateTime math operators, and only use the comparisons. I'd suggest something like:
my $now = DateTime->now( time_zone => 'Pacific/Honolulu' ); my $one_week_from_now = $now->clone->add( weeks=>1 ); if ( $reservation_date > $one_week_from_now ) ...
Update: Corrected ->add( week=>1 ) to ->add( weeks=>1 )!
Update 2: Added ->clone, as suggested by tobyink below. That's what I get for running a different test case (DateTime->now->add(weeks=>1)) than what I posted here :-/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting days with DateTime (updated)
by tobyink (Canon) on Apr 02, 2020 at 07:18 UTC | |
|
Re^2: Counting days with DateTime
by htmanning (Friar) on Apr 01, 2020 at 19:33 UTC | |
|