Page 1 of 1

Minus date not working correctly

Posted: 15 Apr 2024, 20:03
by rdonald18
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

Re: Minus date not working correctly

Posted: 15 Apr 2024, 20:10
by boiler
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.

Re: Minus date not working correctly

Posted: 17 Apr 2024, 02:44
by rdonald18
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.