Dates how to add and substract? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Dates how to add and substract?  Topic is solved

Post by Krd » 24 May 2022, 11:53

Hello,

How to fix this:

Code: Select all

MyDate := "23.05.2019"       
CurrentDate:= format("{}.{}.{}",A_DD,A_MM,A_YYYY)
DayIamAfter := MyDate + 3 years   ;How to add this? So it would be 23.05.2022

   If ( DayIamAfter < CurrentDate )
      {
      MsgBox, The date is older than 3 years as of current date {!}
      }
   Else
      {
      MsgBox, The date is younger than 3 years as of current date {!}
      }

User avatar
Chunjee
Posts: 1422
Joined: 18 Apr 2014, 19:05
Contact:

Re: Dates how to add and substract?

Post by Chunjee » 24 May 2022, 12:17

https://www.autohotkey.com/docs/commands/EnvAdd.htm in the docs covers this :thumbup:
I think years is not usable because ambiguous over with or without leapyear days; therefore I used 3*365

Code: Select all

CurrentDate := 20190523
CurrentDate += 3*365, days
FormatTime, MyDate, CurrentDate, dd.MM.yyyy
msgbox, % MyDate
; => "24.05.2022"

You may need to convert your "23.05.2019" string into YYYYMMDDHH24MISS format before making changes

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Dates how to add and substract?

Post by Krd » 24 May 2022, 12:56

Chunjee wrote:
24 May 2022, 12:17
https://www.autohotkey.com/docs/commands/EnvAdd.htm in the docs covers this :thumbup:
I think years is not usable because ambiguous over with or without leapyear days; therefore I used 3*365

Code: Select all

CurrentDate := 20190523
CurrentDate += 3*365, days
FormatTime, MyDate, CurrentDate, dd.MM.yyyy
msgbox, % MyDate
; => "24.05.2022"

You may need to convert your "23.05.2019" string into YYYYMMDDHH24MISS format before making changes
Thanks for the replay.

Not working for what I want.

I could fix this if there was something like this:

Todays date - 3 years, not days? How could I go back in time 3 years and from todays date?
F.exp
24.05.2022 is showing 24.05.2019
25.05.2022 is showing 25.05.2019
10.07.2022 is showing 10.07.2019
01.01.2023 is showing 01.01.2020
ect..

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Dates how to add and substract?

Post by Krd » 26 May 2022, 11:42

Fixed it the noobs way with a highway of statements! :crazy: :lolno:

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Dates how to add and substract?

Post by flyingDman » 26 May 2022, 12:04

That code does not work. I provide you with a good start here: viewtopic.php?f=76&t=104503&p=464311#p464279
14.3 & 1.3.7

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Dates how to add and substract?

Post by Krd » 26 May 2022, 13:32

flyingDman wrote:
26 May 2022, 12:04
That code does not work. I provide you with a good start here: viewtopic.php?f=76&t=104503&p=464311#p464279
Yes, much appreciated. I used that part too, combined with statements and variables.

Post Reply

Return to “Ask for Help (v1)”