Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Working with times
Message
 
À
04/12/1999 01:23:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00298612
Message ID:
00298614
Vues:
21
>Hi,
>My query is how to work with times in vfp.
>I want to subtract one time from another to get a time difference in hh:mm:ss. For example 10:35:21-05:35:20=05:00:01
>Is this possible?
>
>Thanks in advance
>Mike Mayo
>IRD Pty Ltd
>www.ird.com.au

Mike,

When you subtract one datetime value from another the result is the number of seconds between the two datetimes. If you would like that in the format;

Days Hours:Minutes:Seconds

You can use a routine like this;
PROCEDURE ElapseTime(pdStart, pdEnd)

LOCAL lnSeconds, lndays, lnhours, lnminutes, lnseconds, lcResult

lnSeconds = pdEnd - pdStart

lnDays = INT(lnSeconds/86400)
lnSeconds = lnSeconds - (lnDays*86400)

lnHours = INT(lnSeconds/3600)
lnSeconds = lnSeconds - (lnHours*3600)

lnMinutes = INT(lnSeconds/60)
lnSeconds = lnSeconds - (lnMinutes*60)

lcResult = ALLTRIM(STR(lnDays,5,0)) + " Days " + ;
           PADL(ALLTRIM(STR(lnHours,5,0)),2,"0") + ":" + ;
           PADL(ALLTRIM(STR(lnMinutes,5,0)),2,"0") + ":" + ;
           PADL(ALLTRIM(STR(lnSeconds,5,0)),2,"0")

RETURN lcResult
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform