Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: DateTime days limit

by haukex (Archbishop)
on Apr 20, 2020 at 22:25 UTC ( [id://11115849]=note: print w/replies, xml ) Need Help??


in reply to DateTime days limit

Sounds like you want DateTime's ->truncate method:

use warnings; use strict; use DateTime; my $now = DateTime->new(year=>2020,month=>4,day=>21,hour=>12); my @tests = ( DateTime->new(year=>2020,month=>4,day=>27,hour=>13), DateTime->new(year=>2020,month=>4,day=>28,hour=>11), DateTime->new(year=>2020,month=>4,day=>28,hour=>13), DateTime->new(year=>2020,month=>4,day=>29,hour=>11) ); for my $reservation_date (@tests) { my $fc_days_limit=7; if ($fc_days_limit) { my $days_from_now = $now->clone->add( days=>$fc_days_limit ) ->truncate( to => 'day' ); my $res_date_only = $reservation_date->clone ->truncate( to => 'day' ); if ($res_date_only >= $days_from_now) { print "Error on $reservation_date\n"; } else { print "Reservation $reservation_date is ok\n"; } } } __END__ Reservation 2020-04-27T13:00:00 is ok Error on 2020-04-28T11:00:00 Error on 2020-04-28T13:00:00 Error on 2020-04-29T11:00:00

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-16 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found