in reply to date and time difference

Hi, your technique is ancient, unreliable and unnecessarily complicated.

DateTime::Format::Strptime is the right tool as haukex has noted. Read the documentation about date math carefully.

Here's an example using subtract_datetime():

$ perl -Mstrict -MData::Dumper -MDateTime::Format::Strptime -wE 'my $p + = DateTime::Format::Strptime->new(pattern => "%b %d %T %Y %Z", on_er +ror => "croak"); my ($dt1, $dt2) = map { $p->parse_datetime($_) } ("N +ov 23 22:31:12 2019 GMT", "Mar 19 06:52:23 2020 GMT"); say for ($dt2, + $dt1); say sprintf("%s : %s", $_, $dt2->subtract_datetime($dt1)->{$_ +}) for qw/months days minutes seconds/'
2020-03-19T06:52:23 2019-11-23T22:31:12 months : 3 days : 25 minutes : 501 seconds : 11
You can of course express the delta however you choose, using the correct method calls.

Hope this helps!


The way forward always starts with a minimal test.