Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: I can't subtract one DateTime object from another to get a DateTime::Duration in days

by 1nickt (Canon)
on May 10, 2021 at 23:59 UTC ( [id://11132363]=note: print w/replies, xml ) Need Help??


in reply to I can't subtract one DateTime object from another to get a DateTime::Duration in days

Hi,

how do I get the difference in days between two DateTime objects?

https://metacpan.org/pod/DateTime#$dt-%3Edelta_days($datetime)

The $dt->delta_days method returns a duration which contains only days.

$ perl -MDateTime -E 'my $dt = DateTime->new(year=>2021); say DateTime +->now->delta_days($dt)->in_units("days")' 130

Hope this helps!


The way forward always starts with a minimal test.
  • Comment on Re: I can't subtract one DateTime object from another to get a DateTime::Duration in days
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found