Michael,
Ed and Jim have put you on the straight and narrow if you're working with datetimes. If you're working with time strings then:
If you can be sure that:
1. the time formats are consistent; and
2. the times are always on the same day
then you can parse the strings to get the hours, minutes and seconds into separate variables (or even into one datetime variable) eg:
function timedif
lParameters tcTime1, tcTime2
local ltTime1, ltTime2, lnDifference, lnHours, lnMinutes, lnSeconds, tcTimeDif
ltTime1 = datetime(1999, 01, 01, val(substr(tcTime1, 1, 2)), val(substr(tcTime1, 4, 2)), val(substr(tcTime1, 7, 2)))
ltTime2 = datetime(1999, 01, 01, val(substr(tcTime2, 1, 2)), val(substr(tcTime2, 4, 2)), val(substr(tcTime2, 7, 2)))
* swap the times so we always get a positive difference
if ltTime1 > ltTime2
local ltTempTime
ltTempTime = ltTime1
ltTime1 = ltTime2
ltTime2 = ltTempTime
endif
lnDifference = ltTime2 - ltTime1
lnHours = int(lnDifference/3600)
lnMinutes = int((lnDifference - lnHours * 3600)/60)
lnSeconds = int(lnDifference - lnHours * 3600 - lnMinutes * 60)
tcTimeDif = padl(tran(lnHours), 2, '0') + ':' + ;
padl(tran(lnMinutes), 2, '0') + ':' + ;
padl(tran(lnSeconds), 2, '0')
return tcTimeDif
endfunc
Note that I've not done any parameter verification.
Cheers,
Andrew
>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
If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?
From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."
All my FoxTalk and other articles are available on my
web site.
Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.