How to add weeks to a date

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

How to add weeks to a date

09 Jul 2020, 07:48

How do I add weeks to a given date, say date_given?

I would like to implement the equivalent of following VBA function:

DateAdd("ww", 4, date_given)

This function adds 4 weeks to date_given.

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dateadd-function
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to add weeks to a date

09 Jul 2020, 10:05

Hallo,
Autohotkey unfortunately does not make it so comfortable.
https://www.autohotkey.com/docs/commands/EnvAdd.htm
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: How to add weeks to a date

09 Jul 2020, 10:09

maybe add 28 days

Code: Select all

weeks    :=4
daysx    :=(weeks*7)
dategiven:=a_now
diff     += daysx,days 
formattime,xx,%diff%,yyyy-MM-dd
msgbox,%xx%
return
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to add weeks to a date

09 Jul 2020, 10:29

Well, it shouldn't be too tough to create a full-blown AHK-UserDefinedFunction that can deal with almost if not all interval-formats of that DateAdd()-function.
The main issue I saw was the input-format of the date_given-parameter, but it looks that this can be solved as well ...
https://autohotkey.com/board/topic/18760-date-parser-convert-any-date-format-to-yyyymmddhh24miss/

Good luck :)
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: How to add weeks to a date

09 Jul 2020, 12:03

@BoBo , thanx, DateParse, great script from user polyethene

Code: Select all

;- Converts almost any date format to a YYYYMMDDHH24MISS value.
;- user polyethene 
;- https://autohotkey.com/board/topic/18760-date-parser-convert-any-date-format-to-yyyymmddhh24miss/
;- https://github.com/Paris/AutoHotkey-Scripts/blob/master/DateParse.ahk
;------------------------------------------------
time := DateParse("2:35 PM, 27 November, 2007")
msgbox,%time%
return
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to add weeks to a date

10 Jul 2020, 01:54

Check out @jeesweeg's https://www.autohotkey.com/boards/viewtopic.php?t=65544#add_date . He also mentioned that DateAdd() is a function available in AHK 2.0 !! It might make sense if someone starts coding with AHK to do it with AHK 2.0 (or AHK_H) for exactly that reason. Make up your mind. Good luck :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 187 guests