Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: DateTime issues

by leszekdubiel (Scribe)
on Apr 05, 2020 at 18:44 UTC ( [id://11115100]=note: print w/replies, xml ) Need Help??


in reply to DateTime issues

#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; use Time::Piece; use Time::Seconds; my $reservation_date = localtime->strptime("2020-03-15#", "%Y-%m-%d#") +; print "$reservation_date\n"; my $one_year_from_now = $reservation_date->add_months(-12); if ($reservation_date > $one_year_from_now) { printf "%s is after one year earlier from now that is %s\n", $reservation_date->strftime("%Y-%m-%d"), $one_year_from_now->strftime("%Y-%m-%d"), } my $one_week_from_now = localtime() + ONE_WEEK; if ($reservation_date < $one_week_from_now) { printf "%s is before one week from now that is %s\n", $reservation_date->strftime("%Y-%m-%d"), $one_week_from_now->strftime("%Y-%m-%d %H:%M:%S"), }
result: Sun Mar 15 00:00:00 2020 2020-03-15 is after one year earlier from now that is 2019-03-15 2020-03-15 is before one week from now that is 2020-04-12 20:43:49

Replies are listed 'Best First'.
Re^2: DateTime issues
by haukex (Archbishop) on Apr 06, 2020 at 06:13 UTC
    my $reservation_date = localtime->strptime("2020-03-15#", "%Y-%m-%d#") +; my $one_year_from_now = $reservation_date->add_months(-12); if ($reservation_date > $one_year_from_now) {

    That's a confusing name for that variable, and also that comparison will always be true.

Log In?
Username:
Password:

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

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

    No recent polls found