KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This code finds the difference between today and a fixed date. #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use DateTime (); use DateTime::Duration (); use DateTime::Format::Strptime (); my $date = "23/05-2022"; my $parser = DateTime::Format::Strptime->new( pattern => '%d/%m-%Y', time_zone => 'local', ); $date = $parser->parse_datetime($date); my $today = DateTime->today(time_zone=>'local'); my $d = DateTime::Duration->new($today - $date); print Dumper $d->delta_days; The problem is that is only outputs -22 days. If I do print Dumper $d; I can see the -130 months as well. $VAR1 = bless( { 'seconds' => 0, 'minutes' => 0, 'end_of_month' => 'preserve', 'nanoseconds' => 0, 'days' => -22, 'months' => -130 }, 'DateTime::Duration' ); How do I get it to output the result in days? Doing print Dumper $d->delta_days + $d->delta_months*30; doesn't seam like an elegant solution.
Tags (comma-separated)
Save Edits
Cancel