Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Difference between two dates in years

by vagabonding electron (Hermit)
on May 14, 2013 at 16:41 UTC ( #1033522=note: print w/ replies, xml ) Need Help??


in reply to Difference between two dates in years

Time::Piece is a core module.

#!/perl use strict; use warnings; use Time::Piece; my $datt = Time::Piece->strptime("2012-03-22", "%Y-%m-%d"); my $datf = Time::Piece->strptime("1925-12-22", "%Y-%m-%d"); my $diff = $datt - $datf; my $result = $diff->years; print "$result years\n"; $result = $diff->days; print "$result days\n";

prints:

C:\Perl\bin>perl pm_1033486.pl 86.2496055700018 years 31502 days

See also Time::Seconds for the data values transformation.


Comment on Re: Difference between two dates in years
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (18)
As of 2015-07-07 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls