Minus date not working correctly

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rdonald18
Posts: 2
Joined: 15 Apr 2024, 19:59

Minus date not working correctly

Post by rdonald18 » 15 Apr 2024, 20:03

Hello,

I have the below script that takes 31 days off the current date. This works fine the first time, but the second time takes 62, third time 93 etc. How do I stop this??

Code: Select all

::.td3::
DateMinus31 += -31,days
FormatTime, FormattedDate1, %DateMinus31%, dd-MM-yyyy
FormatTime, CurrentDateTime,, dd-MM-yyyy
    SendInput, %FormattedDate1%{tab}%CurrentDateTime%{Enter}
    Return

User avatar
boiler
Posts: 16999
Joined: 21 Dec 2014, 02:44

Re: Minus date not working correctly

Post by boiler » 15 Apr 2024, 20:10

The += operator adds to the previous value, so it keeps adding -31 to its previous value. Precede that line with DateMinus31 := A_Now so that it starts with today’s date each time.

rdonald18
Posts: 2
Joined: 15 Apr 2024, 19:59

Re: Minus date not working correctly

Post by rdonald18 » 17 Apr 2024, 02:44

boiler wrote:
15 Apr 2024, 20:10
The += operator adds to the previous value, so it keeps adding -31 to its previous value. Precede that line with DateMinus31 := A_Now so that it starts with today’s date each time.
Thankyou so much boiler. That works perfectly now.

Post Reply

Return to “Ask for Help (v1)”