Connecting Tech Pros Worldwide Forums | Help | Site Map

How to find total length of service

Newbie
 
Join Date: Sep 2009
Posts: 3
#1: Oct 1 '09
I am working on an access project for pension calculation. I want to find total length of service between two dates. i.e. if the Date of entry into service is 15/3/1980 and the date of retirement will be 31/1/2010 then the total length of service will be 29 years, 10 months, 17 days.

Kindly help me how to find the length of service in above said format by using VB code in an access project.

kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Posts: 1,155
#2: Oct 2 '09

re: How to find total length of service


well, you can always use the DATEDIFF function
Newbie
 
Join Date: Oct 2009
Posts: 5
#3: Oct 24 '09

re: How to find total length of service


Private Sub cmdCalculate1_Click()
' create a button like cmdCalculate1
' place a Label in form and name it to lblDifference
'Put two Text Boxes one for txtThen for Retd.date
' and one for txtPens_Calculations for Date of Appointment
' Hi ...I am Deaf & National deaf chess player. I like your comments
' Please test this programme throughly. esakkisivaganesh@yahoo.co.in
Dim dtmAppointt As Date, dtmNow As Date
Dim strYear As String, strMOnth As String, strDay As String
Dim strWeekDay As String, strMessage As String

'set the trap
On Error GoTo BadDate
' convert date the user typed in
dtmAppointt = CDate(txtThen.Text) ' Retirement date
'success!
On Error GoTo 0

'txtPens_Calculations.Text = "01/04/" & Year(Now)

' txtPens_Calculations.Text = Format(Now, "dd/mm/yyyy") 'Year(Now)
dtmNow = txtPens_Calculations.Text 'Date of Entry in Service

'difference in years
strYear = Str$(Year(dtmAppointt) - Year(dtmNow))

'difference in months
strMOnth = Str$(Month(dtmAppointt) - Month(dtmNow))

'differnce in days
strDay = Str$(Day(dtmAppointt) - Day(dtmNow))

'get the day of the week
strWeekDay = Format(dtmAppointt, "dddd") ' strWeekday = to find what day today?
strMessage = strYear & " years, " & strMOnth & " months, " & _
strDay & " days; " & Chr$(10) ' put together the label
strMessage = strMessage & "The day of the week you gave is a " & _
strWeekDay & ","
lblDifference.Caption = strMessage
Exit Sub

BadDate:
errMsgBox "Please type a date in the correct format. i.e. 01/30/2000 MM/DD/Year"
txtThen.SetFocus



End Sub
Reply


Similar Visual Basic 4 / 5 / 6 bytes