Simple adding year problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cubedude76
Posts: 1
Joined: 10 Apr 2017, 16:26

Simple adding year problem

10 Apr 2017, 16:31

I'm not sure why this is outputting the current year 2017 in stead of 2018. Any ideas?

Code: Select all

CurrentYear =  %A_Now%
EnvAdd, CurrentYear, 525600 , Minutes ;525600 mins = 1 year
FormatTime, NextYear,CurrentYear , yyyy
msgbox, %NextYear% ;why does this output the current year?
bigdeal
Posts: 66
Joined: 13 Feb 2017, 06:31

Re: Simple adding year problem

10 Apr 2017, 17:10

Im quite curious about this one too actually
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Simple adding year problem

10 Apr 2017, 17:12

Try %CurrentYear% in your format time.

That might work. If not I'll look at it again closer.

Also why not just add 366 days? I guess that doesn't matter.
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Simple adding year problem

10 Apr 2017, 17:14

Code: Select all

; CurrentYear = %A_Now% ; traditional mode to assign a value to a variable
; or
CurrentYear := A_Now  ; expressional mode
EnvAdd, CurrentYear, 525600, Minutes
FormatTime, NextYear, %CurrentYear%, yyyy
msgbox, %NextYear%
bigdeal
Posts: 66
Joined: 13 Feb 2017, 06:31

Re: Simple adding year problem

10 Apr 2017, 17:18

GEV wrote:

Code: Select all

; CurrentYear = %A_Now% ; traditional mode to assign a value to a variable
; or
CurrentYear := A_Now  ; expressional mode
EnvAdd, CurrentYear, 525600, Minutes
FormatTime, NextYear, %CurrentYear%, yyyy
msgbox, %NextYear%
lmao this works!! dude i did the same thing and it didn't work, eh GGWP
TAC109
Posts: 1129
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Simple adding year problem

10 Apr 2017, 18:48

bigdeal wrote:
GEV wrote:

Code: Select all

; CurrentYear = %A_Now% ; traditional mode to assign a value to a variable
; or
CurrentYear := A_Now  ; expressional mode
EnvAdd, CurrentYear, 525600, Minutes
FormatTime, NextYear, %CurrentYear%, yyyy
msgbox, %NextYear%
lmao this works!! dude i did the same thing and it didn't work, eh GGWP
Fails on 1st January of a leap year!
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
User avatar
Coderooney
Posts: 46
Joined: 23 Mar 2017, 22:41

Re: Simple adding year problem

20 Apr 2017, 19:21

You were just missing the % prefix in the third line to force an expression, that's all:

Code: Select all

CurrentYear =  %A_Now%
EnvAdd, CurrentYear, 525600 , Minutes ;525600 mins = 1 year
FormatTime, NextYear, % CurrentYear, yyyy
msgbox, %NextYear% ;why does this output the current year?
Alternatively:

Code: Select all

FormatTime, NextYear, %CurrentYear%, yyyy
Also, why not just this?:

Code: Select all

NextYear := A_YYYY + 1
MsgBox % NextYear
Adding 1 is simpler than adding 525600 and it saves you the extra step of formatting the time as well as working on the 1st of January of a leap year.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, Google [Bot], peter_ahk, Spawnova and 347 guests