Perl : difference between two dates in years

hello folks,

I have a requirement in which I have to calculate the difference of
localdate(today's date) and the given(earlier) date and to check whether the
difference is exactly a year or more than that(can be 1 year or 2 years or 3 years.. ) .

Could anyone please let me know the logic behind this..and also any related module for performing this task..

Example:

today's date :  12/24/2013

given date   :   12/17/2003

In this scenario.. the output is false..

today's date :  12/24/2013

given date   :   12/24/2003

In this scenario the output is true.

what I am thinking is to split to the date and to check the difference..

@todaydate = split("/",$today);
@givendate = split("/",$given);

if ( $todaydate[0] - $givendate[0] == 0 )
{
      if ( $todaydate[1] - $givendate[1] == 0 )
      {
             print "True : the difference is", $todaydate[2]-$datedate[2],"\n" ;
      }

}

Take a look at Date::Calc - search.cpan.org (Delta_YMD function specifically).

1 Like

Thanks bartus11 ..!!!

That is what I am looking for ...!!!