$return = DateAdd({D|W|M|Y},interval,date[,date_format])
Where:
$return |
The date adjusted by the specified interval. |
D |
The interval parameter is the number of days. |
W |
The interval parameter is the number of weeks. |
M |
The interval parameter is the number of months. |
Y |
The interval parameter is the number of years. |
interval |
The number of days, weeks, months or years to add to the date. A positive integer moves the date forward. A negative integer moves the date backward. |
date |
The date to be adjusted. |
date_format |
can be one of the following: DMY ($return and date are in DD/MM/YYYY format.) MDY ($return and date are in MM/DD/YYYY format.) YMD ($return and date are in YYYY/MM/DD or YYYY-MM-DD format.)
date_format may be omitted, in which case the date format is taken from the "Option DateFormat" command. If the "Option DateFormat" command is also omitted, then the date format is assumed to be the system short date format. |
interval, date and/or date_format may be variables.
The DateAdd command adjusts the input date by the specified interval. A positive interval moves the date forward and a negative interval moves the date backward.
Examples
$NewDate = DateAdd(d, 1, "2014-01-01", ymd) ' Returns 2014-01-02
$NewDate = DateAdd(D, -1, "2014-01-01", YMD) ' Returns 2013-12-31
$NewDate = DateAdd(d, 1, "01/01/2014", mdy) ' Returns 01/02/2014
$NewDate = DateAdd(D, -1, "01/01/2014", dmy) ' Returns 31/12/2013
$Tomorrow = DateAdd(d, 1, $DATEYMD, ymd) ' Returns tomorrow's date
$Yesterday= DateAdd(d, -1, $DATEYMD, ymd) ' Returns yesterday's date
$NextWeek = DateAdd(w, 1, $DATEYMD, ymd) ' Returns next week's date
$NewMonth = DateAdd(m, 1, $DATEYMD, ymd) ' Returns next month's date
$NextYear = DateAdd(y, 1, $DATEYMD, ymd) ' Returns next year's date
Sample Script
' DateAdd - Adjust today's date
$LineFeed = Chr(10)
$DateFormat = ymd
$Today = $DATEYMD
$Tomorrow = DateAdd(d, 1, $Today, $DateFormat)
$Yesterday = DateAdd(d,-1, $Today, $DateFormat)
$NextWeek = DateAdd(w, 1, $Today, $DateFormat)
$NewMonth = DateAdd(m, 1, $Today, $DateFormat)
$NextYear = DateAdd(y, 1, $Today, $DateFormat)
MsgBox("Tomorrow = " & $Tomorrow & $LineFeed _
& "Yesterday = " & $Yesterday & $LineFeed _
& "Next Week = " & $NextWeek & $LineFeed _
& "Next Year = " & $NextYear)
exit
See Also:
TN3270 Plus is continually being improved. To learn more about the latest enhancements, please review our Version History web page.