Formattime minutes counting to 99?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
densch
Posts: 120
Joined: 29 May 2018, 15:10

Formattime minutes counting to 99?

30 Jul 2021, 14:38

Hi, in a test script I used this simple piece of code:

Code: Select all

b::
Time1:=20040101035512
Time2:=20040101051316
EnvSub,Time2,Time1
MsgBox %Time2%
return
I would have expected 011804 or 11804 as an output (namely 04 seconds, 18 minutes and 1 hour)
but I got 15804 as a result instead.
my interpretation of that would be that for whatever reason the minutes were counted as if they went from 0-99 instead of the real 0-59.

not sure why though.

does anyone have any idea why this is happening and how to get rid of it?
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Formattime minutes counting to 99?

30 Jul 2021, 15:14

Try:

Code: Select all

Time1 := 20040101035512
Time2 := 20040101051316
EnvSub,Time2,Time1, Seconds

seconds := format("{:02}" , floor(mod(time2 , 60)))     
minutes := format("{:02}" , mod(floor(time2/60) , 60))    
hours  :=  floor(time2/3600)                              

MsgBox % hours ":" minutes ":" seconds
return
14.3 & 1.3.7
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Formattime minutes counting to 99?

30 Jul 2021, 15:44

Don't use floating point if you don't need it:

Code: Select all

Time1 := 20040101035512
Time2 := 20040101051316
EnvSub,Time2,Time1, Seconds

seconds := format("{:02}" , mod(time2, 60))     
minutes := format("{:02}" , mod(time2//60, 60))    
hours  :=  time2//3600                              

MsgBox % hours ":" minutes ":" seconds
return
densch
Posts: 120
Joined: 29 May 2018, 15:10

Re: Formattime minutes counting to 99?

31 Jul 2021, 07:00

I tried the envsub command with Minutes and it will probably do it already for me that way.
Thing is, in the end I wanna check if the time difference is >=50 minutes or if it isnt.
so the minute count is already good enough for my purposes.

I still don't get though why the minutes in formattime weren't counted 0-59 :-/
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: Formattime minutes counting to 99?

31 Jul 2021, 07:04

FormatTime ? Where is it in your code?
But EnvSub sees these integers only as timestamps, if you add a a time unit. If not, it treats them as normal integers.
densch
Posts: 120
Joined: 29 May 2018, 15:10

Re: Formattime minutes counting to 99?

31 Jul 2021, 08:05

gregster wrote:
31 Jul 2021, 07:04
FormatTime ? Where is it in your code?
But EnvSub sees these integers only as timestamps, if you add a a time unit. If not, it treats them as normal integers.
EHm, these dates are obviously in the wanted YYYYMMDDHH24MISS format, so I dont get why envsub won't subtract them as such date stamps? :-/


weirdly enough, it only seems to doing the math correctly if I limit the result to a part like the minutes.
otherwise it doesnt do the math right :-(
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: Formattime minutes counting to 99?

31 Jul 2021, 08:20

Again, Envsub (and the equivalent syntax Var -= Value [, TimeUnits]) just subtracts a number from another one, by default. That's it.
To get the special behaviour that it treats certain numbers as timestamps, you need to add the optional TimeUnits parameter. It's documented.

And no, it doesn't check if an integer could potentially be a timestamp - what about numbers that look accidently like a timestamp ? (See eg example #3, especially because a valid timestamp doesn't need to contain the smaller units like secs, mins, ... per the docs, they'll get filled with default values)
Such guessing could really lead to unexpected behaviour. See the difference ?

Code: Select all

var1 := 2005			; https://www.autohotkey.com/docs/commands/FileSetTime.htm#YYYYMMDD
var2 := 2003
var1 -= var2, days		; EnvSub, var1, var2, days
MsgBox, %var1%  		; 731 (days)

var1 := 2005
var2 := 2003
var1 -= var2			; EnvSub, var1, var2
MsgBox, %var1% 			; 2
If you see EnvSub, Var, Value or the equivalent Var -= Value in a script, there is no clear indication that it would do what you expect, and the docs do not say it either.
(Of course, a command name like FormatTime could indicate that the command handles timestamps - but contrary to its title, this topic doesn't seem to be about that command.)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, doodles333 and 386 guests