Custom Search
 


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:

1.Examples of MS Access DateDiff function used in query and VBA code
2.MS Access DateDiff function
3.How to find out your computer name and username by VBA
4.Examples of MS Access DatePart function
5.MS Access DatePart function
6.Examples of MS Access DateAdd function
7.IIF function basics - the CASE statement of MS Access
8.MS Access Date Expression
9.Solved: MS Access error "The text is too long to be edited"
10.Create MS Access Combo Box essential properties by VBA code
11.Create MS Access Combo Box essential properties manually
12.How to do text search in MS Access programmatically
13.Solved - the size of the Access query result is larger than the maximum size of a database (2 GB)
14.How to easily get a list of field names in MS Access
15.How to count distinct records in MS Access
16.How to do transaction based processing in MS Access
17.How to open a document (local/network file or web page) from MS Access
18.How to use ADOX to create unique composite index - the VBA approach
19.How to do cross-table update queries in MS Access - the right way
20.Three efficient ways to get the number of records by using VBA
21.How to create a composite unique index (not as a primary key) in MS Access
22.Use VBA to get the correct number of records in a Recordset object
23.Disable Access Prompt when a record is changed, table deleted, or action queries run
24.How to hide and unhide a MS Access object
25.How to return multiple values from a VBA function (Part 3)
26.How to return multiple values from a VBA function (Part 2)
27.How to return multiple values from a VBA function (Part 1)
28.Three ways to programmatically duplicate a table in MS Access by VBA
29.Create a DLL by CSharp or VB.Net for VBA
30.How to correctly reference and call a DLL
31.How to register a C# or VB.Net DLL
32.Email address validation by Regular Expressions using VBA
33.Fix MS Access error: Query must have at least one destination field
34.How to unselect radio buttons in MS Access after it has been selected
35.How to Change Query Timeout Value for MS Access SQL Queries
36.What is Northwind Traders database

Copyright © 2024 GeeksEngine.com. All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

 
Home | Feedback | Terms of Use | Privacy Policy