DateAdd
Offset a date with a specified interval
Declare Function DateAdd ( ByRef interval As Const String, ByVal number As Double, ByVal date_serial As Double ) As Double
#include "vbcompat.bi"
result = DateAdd( interval, number, date_serial )
interval
Interval is specified as follows:
The compiler will not recognize this function unless vbcompat.bi or datetime.bi is included.
Syntax
Declare Function DateAdd ( ByRef interval As Const String, ByVal number As Double, ByVal date_serial As Double ) As Double
Usage
#include "vbcompat.bi"
result = DateAdd( interval, number, date_serial )
Parameters
interval
string indicating which period of time corresponds to one unit of number
numberthe number of intervals to add to the base date. The number will be rounded to the nearest integer.
date_serialthe base date
Return Value
Description
Interval is specified as follows:
value | interval |
yyyy | years |
q | quarter(three months) |
m | months |
ww | weeks |
d,w,y | days |
h | hours |
n | minutes |
s | seconds |
The compiler will not recognize this function unless vbcompat.bi or datetime.bi is included.
Example
#include "vbcompat.bi"
Const fmt = "ddddd ttttt"
Dim d As Double
d = Now()
Print "1 hour from now is ";
Print Format( DateAdd( "h", 1, d ), fmt )
Print "1 day from now is ";
Print Format( DateAdd( "d", 1, d ), fmt )
Print "1 week from now is ";
Print Format( DateAdd( "ww", 1, d ), fmt )
Print "1 month from now is ";
Print Format( DateAdd( "m", 1, d ), fmt )
Const fmt = "ddddd ttttt"
Dim d As Double
d = Now()
Print "1 hour from now is ";
Print Format( DateAdd( "h", 1, d ), fmt )
Print "1 day from now is ";
Print Format( DateAdd( "d", 1, d ), fmt )
Print "1 week from now is ";
Print Format( DateAdd( "ww", 1, d ), fmt )
Print "1 month from now is ";
Print Format( DateAdd( "m", 1, d ), fmt )
Differences from QB
- Did not exist in QB. This function appeared in Visual Basic.
See also