Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Timecalc.prg
Message
 
À
23/01/2002 16:28:29
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00609326
Message ID:
00609338
Vues:
10
>Hi,
>
>I need to do some calculations based on time. For example, someone clocks in at 06:00:00 and clocks out at 16:35:00 I need to find out how many hours and minutes they worked that day. I searched on the Microsoft Knowledge Base and found a prg called timecalc. (http://support.microsoft.com/default.aspx?scid=kb;en-us;Q115055)
>
>I tried it out, and I am not sure if its just me - but it seems to be doing wierd things. I looked at the code behind and it makes sense to me so I don't know whats going one.
>
>MESSAGEBOX(timecalc("21:51:00", "21:00:00:", 2))
>returned 0 hours and 9 minutes.
>
>if I tried it the other way
>MESSAGEBOX(timecalc("21:00:00", "21:51:00:", 2))
>returned 0 hours 51 minutes. (correct)
>
>But if I tried
>MESSAGEBOX(timecalc("06:00:00","16:35:00" , 2))
>returns 10 hours and 35 minutes - this is wrong, it should be 10 hour and 25 minutes
>
>the other way
>MESSAGEBOX(timecalc("16:35:00","06:00:00" , 2))
>returns - 10 hours and 25 minutes
>
>So after looking at timecalc.prg the code made sense and I am not sure why I am getting these results. I have been spending lots of time on this project I am working on lately so maybe I am just missing something very simple.
>
>Anyways, is there a better, more reliable way to do what I want to do? Using vfp 7
>
>Thanks!
Chris,

I think I understand what it's doing. As you know, 2 means to subtract one time from another. In the first example, subtracting the smaller from the larger, yields 10 hours 35 minutes. However, in the latter it appears to rely on absolute values to return the 10:25.

I note that the code was written for a time before the Date/Time data type came into being. Subtracting one date/time from another returns the number of seconds. It's a lot easier and faster to convert seconds into days, hours and minutes, than the code shown there. Even if the time is being stored as a string converting it to a Date/Time value then doing the math, is probably a better solution.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform