Pathologically Eclectic Rubbish Lister | |
PerlMonks |
I can't subtract one DateTime object from another to get a DateTime::Duration in daysby Cody Fendant (Hermit) |
on May 10, 2021 at 22:17 UTC ( [id://11132358]=perlquestion: print w/replies, xml ) | Need Help?? |
Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question: Oh the shame: my date objects weren't actually differing by more than one day because I'm an idiot and assumed that my inputs were what I thought they were! Thanks commenters for forcing me to go back and look at exactly what was in the objects. I leave this here as a memorial, or it can be reaped. This is a bug in an application I'm working on. The code creates two DateTime objects and subtracts one from the other to get a DateTime::Duration object. However the DateTime::Duration object can't return a difference in number of days, which is what I need. This is actually expected behaviour: The last example demonstrates that there will not be any conversion between units which don't have a fixed conversion rate. I guess my question is, how do I get the difference in days between two DateTime objects? Updated: The current code just does Where both DateTime objects are specific fixed dates, like I can understand that if I create a duration object with years => 1, months => 15 that's not something where we can be sure of the number of days, but that's not what's happening in my code.
Back to
Seekers of Perl Wisdom
|
|