Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DateTime minus DateTime give me a numeric, want Time Dif
Message
From
11/08/2007 09:19:36
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01247612
Message ID:
01247616
Views:
28
This message has been marked as a message which has helped to the initial question of the thread.
>Hi all
>
>I have 2 DateTime fields which need to be diff.ed as time. VFP returns a numeric value in seconds when I minus one datetime from the other. Can I not have a return value as a time type in hours.mins.secs?
>
>Please advise.

For the following, please note that a datetime, by definition, includes BOTH a date and a time.

If you subtract dt2 - dt1, the difference will be in seconds.

You can add this to any date at midnight, to get the current date + a time that represents the time difference. For example:
TimeDif = dt2 - dt1
TimeDif2 = ttod(date()) + TimeDif
? TimeDif2
? padl(hours(TimeDif2), 2, "0") + ":" + padl(minutes(TimeDif2), 2, "0");
  + ":" + padl(sec(TimeDif2), 2, "0")
The last line won't work correctly if the time difference is >= 24 hours; in this case, you could do the math to extract hours, minutes, and seconds:
TimeDif = dt2 - dt1
lnHours = int(TimeDif / 3600)
TimeDif = TimeDif - 3600 * lnHours
lnMinutes = int(TimeDif / 60)
TimeDif = TimeDif - 60 * lnMinutes
lnSeconds = TimeDif
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform