Jedini problem je taj, što se staž ne računa tako. Uopšte, razlika dva datuma/vremena ne može tako da se računa. Postoje razne funkcije za to, npr. DateDiff(). Ili, malo prilagođeno ovako nešto:
Code:
Public Function GetElapsedInterval(dtStartDate As Date, dtEndDate As Date) _
As String
'Returns a formatted string yielding elapsed time.
'Doesn't handle negative date ranges i.e. dtEndDate > dtStartDate
'Input date/times between two ##, i.e. #9/10/1963 8:30AM#.
' Function works for all date/times between January 1, 100 12:00:00AM
' to December 31, 9999 11:59:59PM
' Use existing Microsoft elapsed time functions
' GetElapsedTime and Age to extend elapsed time to
' include elapsed years and months
'Author: K. Fisher 5/20/1998 fishe...@slcnet.-antispam-net
'Sample usage:
'?basDate.GetElapsedInterval(#1/1/100 10:22PM#,Now())
'1898 Years 4 Months 18 Days 3 Hours 15 Minutes 53 Seconds
'?basDate.GetElapsedInterval(#5/19/1998 11:22:37PM#, #5/20/1998 12:39:54PM#)
'0 Years 0 Months 0 Days 13 Hours 17 Minutes 17 Seconds
Dim dtWorkingDate As Date 'working date/time
'Determine the elapsed years portion
Dim intYears As Integer
intYears = Age(dtStartDate, dtEndDate)
'34 = 9/18/1998 9/10/1963
'Determine the elapsed month portion
dtWorkingDate = DateAdd("yyyy", intYears, dtStartDate)
'9/10/97 8:30:00 PM = 34 years plus 9/10/1963 8:30PM
Dim intMonths As Integer
intMonths = DateDiff("m", dtWorkingDate, dtEndDate)
dtWorkingDate = DateAdd("m", intMonths, dtWorkingDate)
'5/10/98 8:30:00 PM = 8 months plus 9/10/97 8:30:00 PM
'Determine the elapsed days, hours, minutes, seconds portion
Dim dblInterval As Double
dblInterval = dtEndDate - dtWorkingDate
If dblInterval < 0 Then
intMonths = intMonths - 1
dblInterval = Abs(dblInterval + 1)
End If
'9.0766087962984 = 5/19/98 8:00:00 AM - 5/10/98 8:30:00 PM
'Assemble the formatted string
GetElapsedInterval = intYears & " Years " & intMonths & _
" Months " & GetElapsedTime(dblInterval)
End Function
Public Function Age(dtBirthday, dtAgeOnDate) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. dtBirthday > dtAgeOnDate
' Input dates between two ##, i.e. #9/10/1963#.
' Source: Microsoft 1997 Neatcode.mdb
' Example: Debug.Print basDate.Age(#9/10/1963#,Now())
If Month(dtAgeOnDate) < Month(dtBirthday) Or _
(Month(dtAgeOnDate) = Month(dtBirthday) And _
Day(dtAgeOnDate) < Day(dtBirthday)) Then
Age = Year(dtAgeOnDate) - Year(dtBirthday) - 1
Else
Age = Year(dtAgeOnDate) - Year(dtBirthday)
End If
End Function
Iz ovoga izvuci šta ti odgovara.
Pozdrav,
Branislav