Function Reference


_DateAdd

Calculates a new date/time by adding/subtracting a specified number of time intervals from an initial date/time

#include <Date.au3>
_DateAdd ( $sType, $iNumber, $sDate )

Parameters

$sType Time interval to be used:
D - Add/subtract days to/from the specified date
M - Add/subtract months to/from the specified date
Y - Add/subtract years to/from the specified date
w - Add/subtract Weeks to/from the specified date
h - Add/subtract hours to/from the specified date
n - Add/subtract minutes to/from the specified date
s - Add/subtract seconds to/from the specified date
$iNumber Number of intervals to be added/subtracted (use unary minus for subtraction)
$sDate Initial date in the format YYYY/MM/DD[ HH:MM:SS]

Return Value

Success: Calculated date.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - Invalid $sType
2 - Invalid $iNumber
3 - Invalid $sDate

Remarks

Valid initial date must be between "2000/01/01 00:00:00". and "3000/12/31 23:59:59".

The function will not return an invalid date. For example, if 3 months are added to '2004/1/31' then the result will be '2004/04/30'.

See _DateTimeSplit() for other possible variations of the input date format.

Related

_DateDiff, _DateTimeSplit, _DateToDayOfWeek, _DateToDayOfWeekISO, _DateToDayValue, _DayValueToDate

Example

#include <Date.au3>
#include <MsgBoxConstants.au3>

; Add 5 days to today
Local $sNewDate = _DateAdd('d', 5, _NowCalcDate())
MsgBox($MB_SYSTEMMODAL, "", "Today + 5 days: " & $sNewDate)

; Subtract 2 weeks from today
$sNewDate = _DateAdd('w', -2, _NowCalcDate())
MsgBox($MB_SYSTEMMODAL, "", "Today minus 2 weeks: " & $sNewDate)

; Add 15 minutes to current time
$sNewDate = _DateAdd('n', 15, _NowCalc())
MsgBox($MB_SYSTEMMODAL, "", "Current time +15 minutes: " & $sNewDate)

; Calculated eventlogdate which returns second since 1970/01/01 00:00:00
$sNewDate = _DateAdd('s', 1087497645, "1970/01/01 00:00:00")
MsgBox($MB_SYSTEMMODAL, "", "Date: " & $sNewDate)