DateAdd()

Auto Hotkey

DateAdd

Adds or subtracts time from a date-time value.

OutputVar := DateAdd(DateTime, Time, TimeUnits)
Function Example: Yesterday := DateAdd(A_Now,-1,"days")

Parameters

DateTime

A date-time stamp in the YYYYMMDDHH24MISS format.

Time

The amount of time to add, as an integer or floating-point number. Specify a negative number to perform subtraction.

TimeUnits
The meaning of the Time parameter. TimeUnits may be one of the following strings (or just the first letter):
Seconds, Minutes, Hours or Days.

Return Value

If DateTime contains an invalid timestamp or a year prior to 1601, or if Time is non-numeric, an empty string is returned to indicate the error.

Otherwise, a timestamp in YYYYMMDDHH24MISS format is returned.

Remarks

The built-in variable A_Now contains the current local time in YYYYMMDDHH24MISS format.

To calculate the amount of time between two timestamps, use DateDiff.

Related

DateDiff, FileGetTime, FormatTime

Example

; Calculate the date 31 days from now.
later := DateAdd(A_Now, 31, "days")
MsgBox % FormatTime(later)