Convert Metric Date

rtdc

Registered User.
Local time
Today, 05:21
Joined
Feb 27, 2007
Messages
55
Hi All

I need to calculate the period between two Now() dates, fine one from the other and subtract the weekends (business days) but I need to show the result in Days, hours, minutes and the current answer is in metric i.e. 5.72.

How can I convert this to normal time?

Cheers.
 
Your will need some code and recognising that there are 24x60x60 = 86,400 seconds in a day, 0.72 of a day will be 62,208 seconds etc.

Create a form and put a text box and a command button.

Private Sub Command1_Click()

Dim sngTime, sngDays, sngHours, sngMinutes, sngSeconds, sngVar As Single

sngTime = Text0.Value

sngDays = Fix(sngTime) ' = 5

sngVar = sngTime - sngDays ' =0.72

sngSeconds = sngVar * 24 * 60 * 60 ' = 62,208


sngHours = Fix(sngSeconds / 60 / 60) ' = 17

're-use sngVar
sngVar = (((sngSeconds / 60 / 60) - sngHours) * 60) ' = 16.8
sngMinutes = Fix(sngVar) ' = 16

're-use sngVar
sngVar = sngVar - Fix(sngMinutes) ' 0.8
sngSeconds = sngVar * 60


' ANSWER is

MsgBox "The Answer is: " & vbLf & vbLf & _
sngDays & " days " & vbLf & _
sngHours & " hours" & vbLf & _
sngMinutes & " minutes" & vbLf & _
Format(sngSeconds, "#") & " seconds"

End Sub

The function FIX is essentially a truncate of the value. You don't necessarily need to create 6 variables, the values could be compounded but for logic sake its easier to follow.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom