To start with you'll want to add a date/time field to the user table (where login/contact details and such are kept) where the default value is now()
You could then use the DateDiff function, but that can only return the number of days OR months OR years between two dates, so you'll end up with 7839 days or something ludicrous, so you have to be creative... or get someone else to be creative for you.
<%
Dim YearsSince, MonthsSince, DaysSince, JoinDate, JoinDay, NowDay
sql = "SELECT JoinDate FROM tblUser WHERE UserID=" & [whatever]
vrec.open sql,adoCon
JoinDate = vrec("JoinDate")
vrec.close
YearsSince = DateDiff(yyyy,JoinDate,Date)
MonthsSince = DateDiff(m,JoinDate,Date)
'this provides the total months, so we have to account for the number of years that have gone past
MonthsSince = MonthsSince - 12*YearsSince
'if the difference in months is negative then even though the datediff for years may be 1, it is still less than a year between them
if MonthsSince < 0 then
YearsSince = YearsSince - 1
MonthsSince = MonthsSince * -1
end if
'Now we use datepart to wrok out the days
JoinDay = DatePart("d",JoinDate)
NowDay = DatePart("d",Date)
DaysSince = NowDay - JoinDay
'the same applies with any difference in days as difference in months
if DaysSince < 0 then
MonthsSince = MonthsSince - 1
'here you have to account for months of different length, based on whether the month part of the join date is 4,6,9,11 or 1,3,5,7,8,10,12 or 2. This i'm still working on, and i'll post if i can work it out
end if
response.write "This user has been on for " & YearsSince & " years, " & MonthsSince & " months and " & DaysSince & " days."
Edited by ub3rl337ch3ch - 23 May 2005 at 9:45pm