DelphiFAQ Home Search:
General :: Programming :: perl
General questions about perl.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Calculate the differece between two dates

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);
 }
 

Generated 16:02:00 on Oct 16, 2017