Announcement

Collapse
No announcement yet.

Real time and date from elapsed seconds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • John Radford
    replied
    Thats great - working nicely. Thanks for your input.

    John

    Leave a comment:


  • Walt Thompson
    replied
    Hi John;

    At the risk of sounding like a wise guy:

    If only 12354 seconds have elapsed, then it is either still 03/04/09 or, worst case, it is 03:43 AM 03/05/09.

    Leave a comment:


  • Michael Mattias
    replied
    for example, I know 12354 seconds have elapsed from 3/4/2009 1:2:3. What is the time and date?
    My imagination, or does this sound like homework?

    Leave a comment:


  • Peter Lameijn
    replied
    Code:
    #Include "Win32Api.Inc"
    
    Type QuadFILETIME
      nS    As Quad
    End Type
    
    '==================================================================================================
    ' AddSeconds. On entry ST holds time to process, on exit ST holds modified time
    '              (SecsToAdd can also be negative to subtract a value...)
    '--------------------------------------------------------------------------------------------------
    Sub AddSeconds Alias "AddSeconds"(ByRef ST As SYSTEMTIME, ByVal SecsToAdd As Long) Export
      Local QFT As QuadFileTime
      SystemTimeToFileTime ST, QFT
      QFT.nS = QFT.nS + (SecsToAdd * 10000000)
      FileTimeToSystemTime QFT, ST
    End Sub
    
    Function PBMain()
      Local lST As SYSTEMTIME
      lST.wDay    = 4
      lST.wMonth  = 3
      lST.wYear   = 2009
      lST.wHour   = 01
      lST.wMinute = 02
      lST.wSecond = 03
      
      MsgBox Format$(lST.wMonth, "00") & "/" & _
             Format$(lST.wDay, "00")   & "/" & _
             Format$(lST.wYear, "0000") & " - " & _
             Format$(lST.wHour, "00")  & ":" & _
             Format$(lST.wMinute, "00")  & ":" & _
             Format$(lST.wSecond, "00"),, "Before:"
    
      AddSeconds lSt, 12354
      
      MsgBox Format$(lST.wMonth, "00") & "/" & _
             Format$(lST.wDay, "00")   & "/" & _
             Format$(lST.wYear, "0000") & " - " & _
             Format$(lST.wHour, "00")  & ":" & _
             Format$(lST.wMinute, "00")  & ":" & _
             Format$(lST.wSecond, "00"),, "After:"
      
      End Function

    Leave a comment:


  • Bud Meyer
    replied
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    
    FUNCTION PBMAIN () AS LONG
        LOCAL st AS SYSTEMTIME
        LOCAL ft AS FILETIME
        LOCAL quadtime AS QUAD
        LOCAL elapsedseconds AS LONG
    
        'starting date/time
        st.wYear   = 2009
        st.wMonth  = 7
        st.wDay    = 24
        st.wHour   = 17
        st.wMinute = 20
        st.wSecond = 30
    
        'number of seconds to add
        elapsedseconds = 5000
    
        'convert to filetime and then convert to quad value so we can do math
        SystemTimeToFileTime(st, ft)
        quadtime = MAK(QUAD, ft.dwLowDateTime, ft.dwHighDateTime)
        'add the seconds (expressed as the number of 10ns intervals)
        quadtime = quadtime + elapsedseconds * 10000000  'multiple seconds by 10,000,000 to convert to amount of 10ns chunks
    
        'convert back into filetime and then system time to get the resulting date/time
        ft.dwLowDateTime  = LO(DWORD, quadtime)
        ft.dwHighDateTime = HI(DWORD, quadtime)
        FileTimeToSystemTime(ft, st)
    
        ? FORMAT$(st.wYear) & "/" & FORMAT$(st.wMonth) & "/" & FORMAT$(st.wDay) & " - " & FORMAT$(st.wHour) & ":" & FORMAT$(st.wMinute) & ":" & FORMAT$(st.wSecond)
    END FUNCTION

    Leave a comment:


  • Edwin Knoppert
    replied
    Search msdn for:

    SystemTimeToVariantTime() and VariantTimeToSystemTime()
    It will return a double and will let you add days easily.
    or by SYSTEMTIME structure, no problem..

    Leave a comment:


  • John Radford
    replied
    What I need to determin is the time and date, based on the number of seconds elapsed from a known time/date. This is dealing with historic time/date data, not current time/date.

    So for example, I know 12354 seconds have elapsed from 3/4/2009 1:2:3. What is the time and date?

    Leave a comment:


  • Michael Mattias
    replied
    You could start with the DATE$ and TIME$ function. That tells you what date and time it is now, in LOCAL date/time.

    But.... Since there are no PB-intrinsic functions to convert to UTC, instead of DATE$ and TIME$ you can use the Windows API function "GetSystemTime()" to get the current time in UTC.

    You can take your known "start date and time" (which I assume from the question you have in UTC) and just do "date and time arithmetic."

    Search here (Source Code Forum) for "Time" and "Date" functions to get the difference in many units of measure. There are multiple contributions from which to choose.

    MCM

    Leave a comment:


  • John Radford
    started a topic Real time and date from elapsed seconds

    Real time and date from elapsed seconds

    Is there a way to convert the number of seconds that have elapsed since an initial known starting time/date, to a real time and date (UTC)?
Working...
X