is there a function to determine the number of days between dates. For example 04/15/2010 - 03/16/2010 is 29 days. How can I determine this in a function. date format will be 04/15/2010, 03/15/2010.
Thanks for the help.
FUNCTION CALCJOUR(WDA1,WDA2) // CALCUL NOMBRE DE JOURS ENTRE 2 VARIABLES // WDA1 ET WDA2 FORMAT JJ/MM/AAAA
LOCAL WJOURS := 0
WJOURS := (CTOD(WDA2) - CTOD(WDA1))
IF WJOURS < 0
WJOURS := 0
ENDIF
RETURN(WJOURS)
hag wrote:is there a function to determine the number of days between dates. For example 04/15/2010 - 03/16/2010 is 29 days. How can I determine this in a function. date format will be 04/15/2010, 03/15/2010.
Thanks for the help.
Function Date360(FirstDate, SecondDate)
LOCAL FirstDay, SecondDay, Date360
DO Case
Case Day(FirstDate)=31
FirstDay := 30
Case Day(FirstDate)=28 .OR. Day(FirstDate)=29
If Month(FirstDate) = 2
FirstDay := 30
Else
FirstDay := Day(FirstDate)
EndIf
OTHER
FirstDay := Day(FirstDate)
EndCASE
DO Case
Case Day(SecondDate)=31
SecondDay := 30
Case Day(SecondDate)=28 .OR. Day(SecondDate)=29
If Month(SecondDate) = 2
SecondDay := 30
EndIf
OTHER
SecondDay := Day(SecondDate)
EndCASE
Date360 := ((DateDiff(FirstDate, SecondDate) - 1) * 30) + ;
(30 -FirstDay) + SecondDay
Return Date360
Function DateDiff(FirstDate, SecondDate)
Return ((year(SecondDate)*12)+Month(SecondDate))-((year(FirstDate)*12)+Month(FirstDate))
The number of days between date1 and date2 (inclusive) is date2 - date1 + 1
A common programming error is to forget to add the extra 1 (that is the interval between 10th March and 11th March inclusive in the same year is 2 days not 1 day).
FUNCTION AgeInYears( dFromDate, dToDate )
LOCAL nYearDiff
nYearDiff := Year( dToDate ) - Year(dFromDate )
IF Month( dToDate ) > Month( dFromDate )
RETURN nYearDiff
ENDIF
IF Month( dToDate ) < Month( dFromDate )
RETURN nYearDiff - 1
ENDIF
// if we reach here we are in the month of birth date
IF Day( dToDate ) >= Day( dFromDate )
RETURN nYearDiff
ELSE
RETURN nYearDiff - 1
ENDIF
FUNCTION AgeAsAtToday( dDOB )
RETURN AgeInYears( dDOB, DATE() )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 11 guests