Skie
-
Total Posts
:
58
- Scores: 0
-
Reward points
:
0
- Joined: 3/2/2006
-
Status: offline
|
Function: Fraction of Day to Time
Friday, September 22, 2006 11:32 AM
( permalink)
This is useful when pulling times from Excel or another program that stores time values in fractions of a day. Function Frac2Time(iDayValue)
'iDayValue is the time when stored as a fraction of a day. (0 = 12:00:00 AM, .875 = 9:00:00 PM, etc.)
If iDayValue >= 0 and iDayValue < 1 Then
'Fractions of a day cannot be negative and must be less than 1.
OneSec = 1/24/60/60
'One second converted to a fraction of a day
TotalSecs = iDayValue/OneSec
'Time in seconds
Secs = TotalSecs Mod 60
TotalMins = (TotalSecs - Secs)/60
'Time in whole minutes
Mins = TotalMins Mod 60
Hours = cInt((TotalMins - Mins)/60)
Frac2Time = FormatDateTime(Hours & ":" & Mins & ":" & Secs)
'Returns time
Else
wscript.echo "Invalid fraction of day."
Frac2Time = -1
'Returns -1 if invalid fraction of day
End If
End Function Example of Calling Function: Set objWorkbook = objExcel.Workbooks.Open ("C:\test.xls")
ExcelTime = Frac2Time(objExcel.Cells(1,1).Value)
If ExcelTime <> -1 wscript.echo ExcelTime
objExcel.Quit
|
|
|
|