Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Function (Return Months/Days between two dates)

Status
Not open for further replies.

TinLegs

Programmer
Jan 14, 2003
100
NZ
Hi all, does anyone know a date function to return the difference between two dates in (Months, Days) or (Years, Months, Days). Days do not have to be accurate ie. 30 days per month would be close enough for what I need. AGE(FromDate,ToDate) is not giving me the result I want. Thanks.
 
Hi,

The code below will give you the number of years, months, days:

Assuming Date1 and Date2 are 2 clarion dates (ie two long)

NbYears#=Year(Date2)-Year(Date1)
Date1=Date(Month(Date1),Day(Date1),Year(Date1)+nbYears#)
NbMonth#=month(Date2) - month(Date1)
If NbMonth# < 0 Then
NbYears#=NbYears# - 1
NbMonth#=NbMonth# + 12
End
Date2=Date(Month(Date2)+NbMonth#,Day(Date2),Year(Date2))
nbDays#=Day(Date2) - Day(Date1)
If nbDays# < 0 Then
NbMonth# = NbMonth# - 1
If NbMonth# < 0 Then
NbYears# = NbYears# - 1
NbMonth# = NbMonth# + 12
End
nbDays# = nbDays# + Day(Date1)
End
Message(NbYears#&'|'&NbMonth#&'|'&nbDays#)

I have not tested it, but it should work after a bit of debug...

Valery.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top