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