Function Reference


_DateAdd

Calculates a new date based on a given date and add an interval

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

Parameters

$sType of one the following:
D - Add number of days to the given date
M - Add number of months to the given date
Y - Add number of years to the given date
w - Add number of Weeks to the given date
h - Add number of hours to the given date
n - Add number of minutes to the given date
s - Add number of seconds to the given date
$iValToAdd number to be added
$sDate Input date in the format YYYY/MM/DD[ HH:MM:SS]

Return Value

Success: Date newly calculated date.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - Invalid $sType
2 - Invalid $iValToAdd
3 - Invalid $sDate

Remarks

The function will not return an invalid date.
When 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)