WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: 1bosborn on February 24, 2021, 12:46:57 PM

Title: I may be misunderstanding TimeDiff
Post by: 1bosborn on February 24, 2021, 12:46:57 PM
I'm trying to determine if a file is over 10 minutes old using TimeDiff:
timenow = YmdHms()
filetime = FileTimeYmdHms(filename)
fileage = TimeDiff(timenow,filetime)
If fileage < 0000:00:00:00:10:00
do stuff
EndIf
The If statement evaluates true even if the file is older. I added a message statement for troubleshooting and it said fileage was 0000:00:00:00:12:17 yet Debug said "If do true" and the script did the stuff it should have if the file were less that 10 minutes old.
Thoughts or advice?
Thanks as always.
Title: Re: I may be misunderstanding TimeDiff
Post by: JTaylor on February 24, 2021, 01:17:14 PM
Put quotes around the value and see if that helps.

Jim
Title: Re: I may be misunderstanding TimeDiff
Post by: 1bosborn on February 24, 2021, 01:50:33 PM
Well now I just feel silly. That worked like a charm, thanks.
Title: Re: I may be misunderstanding TimeDiff
Post by: td on February 24, 2021, 02:17:02 PM
It is a bit confusing. The colon is the concatenation operator so 0000:00:00:00:10:00 reads as a bunch of numbers that are concatenated to each other with the result being the string "00001000".  The reason some of the leading zeros are dropped is that the integer 0000 or 00 are both read as the integer 0 before being converted to a string. The extra zeros have no significance in integer constants.