DelphiFAQ Home Search:

Calculate the differece between two dates

 

comments1 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

Here's a function that calculates the difference between 2 dates that are available as 3 integers (e.g. 5th of April 2003 would be passed as 2003,4,5).

This routine does not take leap years into account.

@monthnames = ('Jan','Feb','Mar',
               'Apr','May','Jun',
               'Jul','Aug','Sep',
               'Okt','Nov','Dez');
@monthdays = (0,31,59,90,120,151,181,212,243,273,303,334);

#==============================================================================
# difference between 2 dates:
# 2003-8-1   and    2003-7-29   -->
# ddiff(2003,8,1,2003,7,29) = 3
sub ddiff {
  local($ny,$nm,$nd,$oy,$om,$od) = @_;
  return ($ny-$oy) * 365 + $monthdays[$nm-1]-$monthdays[$om-1] + ($nd-$od);
}

Comments:

2007-01-26, 09:21:53
anonymous from Falls Church in Virginia, United States  
rating
This article gave the exact formula i was looking for after 2 days of my rigorous search of date functions on web for perl. Thankyou so much.

Cheers!!

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.