Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: DateCalc using Date::Manip

by 1nickt (Canon)
on Jan 10, 2017 at 13:00 UTC ( [id://1179303]=note: print w/replies, xml ) Need Help??


in reply to DateCalc using Date::Manip

Hi tsdesai

I am trying to count days between two dates ...

You can use DateTime's delta_days() method for this.

$ perl -Mwarnings -Mstrict -ML -E' my $parser = DateTime::Format::Strptime->new(pattern => "%Y%m%d%H:%M:% +S", on_error => "croak"); my $dt1 = $parser->parse_datetime("2016080100:00:00"); my $dt2 = $parser->parse_datetime("2016123100:00:00"); say $dt2->delta_days( $dt1 )->in_units("days"); '
Output:
152
[ Note that you still have to use in_units() because delta_days() returns a DateTime::Duration object (with all values rolled into a whole number of days). ]

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-18 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found