MS Access DateAdd function
DateAdd function can be used in both Access queries and VBA code. It adds or subtracts a specified time interval from a
date/time value and returns a new date/time value after the addition or subtraction. The format of the return value for
DateAdd is determined by
Control Panel settings, not by the format that is passed in date argument.
For example, if today is the date of an order is placed, you can add 30 days onto today's date and get the date
the order must be shipped.
Click the link below to see examples of how to use DateAdd function:
Access queries example
DateAdd function syntax:
DateAdd (interval, number, date)
Function Parameters:
Parameter |
Required / Optional |
Description |
interval |
Required |
Interval is the abbreviation for a specific part of a date/time value you want to add.
Note: if you want to add days to another date value, the interval you specify can be either of
the following three settings and you will get the same result.
- y (Day of year): DateAdd("y", 10, OrderDate)
- d (Day of month): DateAdd("d", 10, OrderDate)
- w (Weekday): DateAdd("w", 10, OrderDate)
The interval parameter settings:
Setting |
Description |
yyyy |
Year (four-digit number) |
q |
Quarter of year |
m |
Month |
y |
Day of year |
d |
Day of month |
w |
Weekday |
ww |
Week of year |
h |
Hour |
n |
Minute |
s |
Second |
|
number |
Required |
This is a number (an integer or long value) that represents the number of intervals you want to add.
It can be positive (to get dates in the future) or negative (to get dates in the past). If it is not an integer or
long value, it is rounded to the nearest whole number before being evaluated.
An integer value is a 2-byte (16-bit) number ranging in value from -32,768 to 32,767.
A long value is a 4-byte (32-bit) number ranging in value from -2,147,483,648 to 2,147,483,647
|
date |
Required |
This is the date/time value to which the interval is added.
The value can be a field name with a Date/Time data type, a variable of date data type in VBA, or a date literal.
A variable is an unknown value at design time but will be dynamically assigned a specific value
at program run-time.
Date literal is a known value of any sequence of characters with a valid format that is surrounded by number signs (#)
such as such as #7-Nov-93#. Valid formats include the date format specified by the date locale settings
(in Control Panel's Regional Options) for your code or the universal date format.
For example, #12/31/92# is the date literal that represents December 31, 1992, where English-U.S. is
the locale setting for your application. Use date literals to maximize portability across national languages.
|
Copyright© GeeksEngine.com
| Other Recent Articles from the MS Access category:
|