viewpoint-particle

Author Topic: I may be misunderstanding TimeDiff  (Read 276 times)

1bosborn

  • Newbie
  • *
  • Posts: 14
I may be misunderstanding TimeDiff
« 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.

JTaylor

  • Pundit
  • *****
  • Posts: 1743
    • Data & Stuff Inc.
Re: I may be misunderstanding TimeDiff
« Reply #1 on: February 24, 2021, 01:17:14 pm »
Put quotes around the value and see if that helps.

Jim

1bosborn

  • Newbie
  • *
  • Posts: 14
Re: I may be misunderstanding TimeDiff
« Reply #2 on: February 24, 2021, 01:50:33 pm »
Well now I just feel silly. That worked like a charm, thanks.

td

  • Tech Support
  • *****
  • Posts: 3945
    • WinBatch
Re: I may be misunderstanding TimeDiff
« Reply #3 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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade