>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)