Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Minutes between 2 dates
Message
De
25/03/2016 18:45:26
 
 
À
25/03/2016 13:15:33
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01633746
Message ID:
01633783
Vues:
48
>>>>>Anyone know of an easy way to calculate the number of minutes between 2 dates. I am trying to store the elapsed time between 2 events
>>>>>
>>>>>Thanks
>>>>>
>>>>>Colin
>>>>
>>>>If you have 2 datetime values, the difference will be in seconds and you can divide by 60 to get the minutes.
>>>>
>>>>If you're using 2 date values, the difference will be in dates, and you can multiply by 24*60 to get minutes.
>>>
>>>Only if the day is 24*60*60 seconds long. It might be different sometimes, to be precise. You also have to check for time zones
>>>
>>>https://www.youtube.com/watch?v=-5wpm-gesOY
>>>
>>>:D
>>>
>>>And. not to forget, DST.
>>
>>You wouldn't need to worry about that if your timestamps are in Universal Time.
>
>I know. It will still not help to include shift-seconds, but it's a start. Also you loose all the nice build-in VFP functions.
>
>:(

You could call the API function GetSystemTime to get the time in Universal Time (in binary format) to construct the VFP datetime value. From that point you can use all the nifty VFP built-in functions for handling datetime values.
FUNCTION UTDateTime
    LOCAL cBuf,lnYr,lnMo,lnDy,lnHr,lnMi,lnSc, ltRet

    DECLARE GetSystemTime IN Win32API AS GetSystemTime ;
        STRING @cBuf
    cBuf = REPLICATE(CHR(0),8*2)
    =GetSystemTime(@cBuf)
    lnYr = ASC(SUBSTR(m.cBuf,2,1))*0x100+ASC(SUBSTR(m.cBuf,1,1))
    lnMo = ASC(SUBSTR(m.cBuf,4,1))*0x100+ASC(SUBSTR(m.cBuf,3,1))
    lnDy = ASC(SUBSTR(m.cBuf,8,1))*0x100+ASC(SUBSTR(m.cBuf,7,1))
    lnHr = ASC(SUBSTR(m.cBuf,10,1))*0x100+ASC(SUBSTR(m.cBuf,9,1))
    lnMi = ASC(SUBSTR(m.cBuf,12,1))*0x100+ASC(SUBSTR(m.cBuf,11,1))
    lnSc = ASC(SUBSTR(m.cBuf,14,1))*0x100+ASC(SUBSTR(m.cBuf,13,1))
    IF BETWEEN(m.lnYr,1900,2100) ;
            .AND. BETWEEN(m.lnMo,1,12) ;
            .AND. BETWEEN(m.lnDy,1,31) THEN
        ltRet = DATETIME(m.lnYr,m.lnMo,m.lnDy,m.lnHr,m.lnMi,m.lnSc)
    ELSE
        ltRet = DTOT({})
    ENDIF
    RETURN m.ltRet
ENDFUNC  && UTDateTime

-5wpm-gesOY
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform