MS Access DateSerial() Function

The DateSerial() function in MS Access creates a date value from its constituent parts: year, month, and day. This is particularly useful when you need to generate dates programmatically, such as in queries or VBA code.



DateSerial(): Definition and Usage

Instead of manually typing a date as text, DateSerial() lets you build a date value using numerical values for each component (year, month, day). This offers better control and allows you to easily calculate dates based on other values.

Syntax

Syntax

DateSerial(year, month, day)
      

Parameter Values

Parameter Description
year The year (a four-digit number). This is required.
month The month (a number from 1 to 12, where 1 is January). This is required.
day The day (a number from 1 to 31, depending on the month). This is required.

Examples

Creating a Date

This example creates the date April 20th, 2017.

Syntax

SELECT DateSerial(2017, 4, 20);
      
Output

2017-04-20  (The exact format might vary slightly depending on your regional settings)
      

Creating a Date with Calculations

You can perform calculations directly within the function's arguments. Note that this example demonstrates subtracting values to create the date.

Syntax

SELECT DateSerial(2017 - 10, 4 - 1, 20 - 5);
      
Output

2007-03-15 (The exact format might vary slightly depending on your regional settings)