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.
Imposible to substract a date
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Imposible to substract a date
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
Re: Imposible to substract a date
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).
Re: Imposible to substract a date
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.
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.
Re: Imposible to substract a date
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
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
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: Lamron750 and 236 guests