WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Time - Timer and Date Functions
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

TimeDiff Unable to Subtract Values

 Keywords: TimeDiff Unable Subtract Values Time Imtestamp 

Question:

I have a script that uses FileYmdHms to get a file timestamp and TimeYmdHms() to get the current time and then 'If TimeDiff(current, timestamp) > "0000:00:00:06:00:00"' to let me know if the file is over 6 hours old. I use the same script 8 consecutive times and also the same code in a number of other scripts. I very routinely get an error that TimeDiff can't subtract the values provided but never in the same script or iteration. Since I'm using functions to create the values I assume (dangerous as it may be) that they are creating valid date-time strings. Any thoughts on why it fails sometimes and not others and more importantly, how to correct it?

Answer:

#DefineFunction udfTimeDiff (strYmdHms1, strYmdHms2)
; Make valid datetime strings.
strYmdHms1 = TimeAdd ("0000:1:1", strYmdHms1)
strYmdHms2 = TimeAdd ("0000:1:1", strYmdHms2)
; Compare datetime strings.
If strYmdHms1 > strYmdhms2 Then Return TimeDiff (strYmdHms1, strYmdhms2)
Return TimeDiff (strYmdHms2, strYmdhms1)
#EndFunction

; Test.

strYmdHms1 = "0:0:0:0:5:32" ; invalid date
strYmdHms2 = "0:0:0:0:3:10" ; invalid date

strYmdHmsDiff1 = udfTimeDiff (strYmdHms1, strYmdHms2) ; "0000:00:00:00:02:22"
strYmdHmsDiff2 = udfTimeDiff (strYmdHms2, strYmdHms1) ; "0000:00:00:00:02:22"

Exit



Article ID:   W18303
Filename:   TimeDiff Unable to Subtract Values.txt
File Created: 2012:06:27:08:48:06
Last Updated: 2012:06:27:08:48:06