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

In reply to Re: DateTime days limit by haukex
in thread DateTime days limit by htmanning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.