Imposible to substract a date

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Diego
Posts: 10
Joined: 12 Dec 2017, 05:14

Imposible to substract a date

12 Dec 2017, 05:36

Hi everyone.

I am completely stuck trying to substract a number of days (say, 280) to a date... And I really don´t know what can be the problem.

For example, if I use "envsub":

today = %A_Now%
envsub, today, 280, days
FormatTime, today, %today%, yyyy-MM-dd
MsgBox, %today%
return

I get this error message in the second line:
: ==> Parameter #2 invalid.
Specifically: 280

Funnily enough, the same thing works absolutely fine if I add it (using "envadd") instead of substracting it:

today = %A_Now%
envadd, today, 280, days
FormatTime, today, %today%, yyyy-MM-dd
MsgBox, %today%
return

I have also tried the normal way, justs using "-=", but I get exactly the same error message:

today = %A_Now%
today -= 280, days
FormatTime, today, %today%, yyyy-MM-dd
MsgBox, %today%

Again, it works perfectly fine with "+=":

today = %A_Now%
today += 280, days
FormatTime, today, %today%, yyyy-MM-dd
MsgBox, %today%

I had version AutoHotkey_1.1.25.02 and have unistalled it and installed instead the latest one, AutoHotkey_1.1.26.01, just in case, but I am getting exactly the same results.

I am using:
- Windows Vista Home Premium Service Pack 2
- 32 bits operating system.

I am completely at odds with this...
Any help or ideas about how to fix it will be more than wellcome.

Cheers.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Imposible to substract a date

12 Dec 2017, 06:00

You were very close! You can't use EnvSub for most date values (see the last line of text for the TimeUnits parameter). Use +=, but simply make the value negative.

Code: Select all

today:=a_now
today+=-240,days
formatTime,todayF,today,yyyy-MM-dd
msgbox % todayF
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Imposible to substract a date

12 Dec 2017, 06:01

Luckily reading our favourite manual is free of charge so let's try it again ... ;)
To add or subtract a certain number of seconds, minutes, hours, or days from a timestamp, use EnvAdd (subtraction is achieved by adding a negative number).
Diego
Posts: 10
Joined: 12 Dec 2017, 05:14

Re: Imposible to substract a date

13 Dec 2017, 04:17

Thanks so much.
Problem solved :) .

Of course first thing I did was to read the manual... But I quitted once I read the value could be any integer. :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Imposible to substract a date

13 Dec 2017, 04:40

The names are slightly misleading:
EnvAdd increases/decreases a date by n seconds(/minutes/hours/days).
EnvSub returns the difference between two dates in seconds(/minutes/hours/days).
In AHK v2, the names are a bit clearer: DateAdd and DateDiff.

Link:
Syntax for time calculations - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39684
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: MiM, ntepa, supplementfacts and 141 guests