Function: Fraction of Day to Time

Author Message
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)
0
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

 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9