tag:blogger.com,1999:blog-7760425276056032223.post7640611598496024241..comments2023-03-19T05:45:18.791-07:00Comments on PLABO: Calculate years between two dates with PerlPablo Marin-Garciahttp://www.blogger.com/profile/17942399687345864870noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7760425276056032223.post-37425519202694337352012-04-05T16:49:23.493-07:002012-04-05T16:49:23.493-07:00@LeoNerd, If you have zillions of dates to process...@LeoNerd, If you have zillions of dates to process or you don't mind to equate all years to 60*60*24*365 secs, using strptime/mktime is ok.<br /><br />But just in case you need a bit more of versatility and you can afford to use some extra modules and some extra function calls then using DateTime is a good tool to use. Do calculations between dates is very tricky so I always suggest to use DateTime as a first option BUT if someone knows what he is doing and have good reasons not to use DateTime then he must not use it.Pablo Marin-Garciahttps://www.blogger.com/profile/17942399687345864870noreply@blogger.comtag:blogger.com,1999:blog-7760425276056032223.post-62956308177137022782012-04-03T10:28:02.074-07:002012-04-03T10:28:02.074-07:00How about simply strptime/mktime them both, subtra...How about simply strptime/mktime them both, subtract, divide by 60*60*24*365.<br /><br />The trouble with your "how many years between" question is it's slightly ill-defined anyway, with respect to the definition of a year. How long in fractional years between January 1st 2010 and January 1st 2011? How long between the same in 2012 and 2013 - I'll remind you 2012 was a leap year and 2010 was not.<br /><br />Do we take a year as 365 days, 365.26 days, some other value? Do we count the number of New Years Eve/New Years Day boundaries we cross between the two dates?LeoNerdhttps://www.blogger.com/profile/06161372680495361467noreply@blogger.com