Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to calculate elapsed time
Message
From
25/05/2005 03:15:59
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01016916
Message ID:
01017383
Views:
14
>>>>>Wow <g>. I didn't even think of that. I need to learn to find simple solutions myself and not to bother people with my silly questions.
>>>>>Thank you very much.
>>>>
>>>>Don't worry, there is no problem to ask if you don't know something.
>>>>
>>>>BTW, if you want to format the difference so that it also appears as a DateTime value, you might add it to a midnight DT value. The date part, of course, would be irrelevant.
>>>
>>>No, I need the result in seconds (actually in hours which is easy to convert).
>>>Thank you very much.
>>
>>What's to convert?
>>
>>cTime = TTOC({^2005/01/01 00:00}+nSeconds,2)
>>
>>Take whatever portion of it you need with LEFT() or SUBSTR().
>
>Fred,
>
>I am no sure I understand your suggestion. I was looking for a way to find difference between two T-type values in hours. Hilmar's suggestion works very well. But I don't see how the method you show will help me. What am I missing?
>
>Thank you for your suggestion.

Dmitry,
PMFJI to eloborate it,
-subtracting 2 datetime values you have difference in seconds.
-considering midnight as starting point - hour 0 - if you add those seconds to midnight you get a new datetime value. Date portion is not important. Hour portion gives you a 'converted' form of those seconds to hours. ie: If seconds were 7200 it would be 2 hours. Add 7200 to midnight and you've ^YYYY/MM/DD 02:00 AM. Ttoc(dt, 2) gives you the time portion '02:00 AM'.

Fred,
Hope you wouldn't mind, a little shortening (and then making it longer for independency to time formats):

ttoc(ctot('0') + nSeconds,2) && also works as a shorter notation - VFP uses base date

However this depends on time format settings and is only effective if elapsed time is not more than 24 hours. My suggestion is to use a longer independant way:
lcHoursMins = ltrim(str(int(m.nSeconds/3600))) + ':'+ltrim(str(m.nSeconds%3600/60))
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform