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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Week Calculation 1

Status
Not open for further replies.

rgeinosky

Technical User
Aug 17, 2000
6
US
I use the following code to calculate time to retirement. It gives me an answer in Months and Days. Can anyone tell me how to calculate in Weeks and Days?

Thanks in advance for your efforts.
Bob
--------------------------------------------------------
Private Sub Command20_Click()
Dim strInterval As String
Dim Date1 As Date ' (Todays Dats)
Dim Date2 As Date ' (Date of Retirement)
Dim bolShowZero As Boolean
Dim varDiff As Variant

strInterval = ""


Me![ckMonths].SetFocus

If Me![ckMonths] Then
strInterval = strInterval & "m"
End If

Me![ckDays].SetFocus

If Me![ckDays] Then
strInterval = strInterval & "d"
End If

Me![ckZero].SetFocus

If Me![ckZero] Then
bolShowZero = True
End If

Me![txtDate1].SetFocus

If Me![txtDate1].Value <> "" Then
Date1 = Me![txtDate1].Value
Else

MsgBox "Please enter a beginning date."

Exit Sub

End If

Me![txtDate2].SetFocus
If Me![txtDate2].Value <> "" Then
Date2 = Me![txtDate2].Value

Else

MsgBox "Please enter an end date."
Exit Sub

End If

varDiff = Diff2Dates(strInterval, Date1, Date2, bolShowZero)

Me![txtResult].SetFocus
Me![txtResult].Value = varDiff
End Sub
 
Quick and dirty:
MsgBox (Date2-Date1)\7 & "w " & (Date2-Date1) Mod 7 & "d"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks much for your help, it worked perfectly.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top