totn Access Functions

MS Access: Format Function (with Dates)

This MSAccess tutorial explains how to use the Access Format function (as it applies to date values) with syntax and examples.

Description

The Microsoft Access Format function takes a date expression and returns it as a formatted string.

Syntax

The syntax for the Format function in MS Access is:

Format ( expression, [ format, [ firstdayofweek, [firstweekofyear] ] ] )

Parameters or Arguments

expression
The value to format.
format

Optional. It is the format to apply to the expression. You can either define your own format or use one of the named formats that Access has predefined such as:

Format Explanation
General Date Displays date based on your system settings
Long Date Displays date based on your system's long date setting
Medium Date Displays date based on your system's medium date setting
Short Date Displays date based on your system's short date setting
Long Time Displays time based on your system's long time setting
Medium Time Displays time based on your system's medium time setting
Short Time Displays time based on your system's short time setting
firstdayofweek

Optional. It is a value that specifies the first day of the week. If this parameter is omitted, the Format function assumes that Sunday is the first day of the week. This parameter can be one of the following values:

Constant Value Explanation
vbUseSystem 0 Uses the NLS API setting
VbSunday 1 Sunday (default, if parameter is omitted)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
firstweekofyear

Optional. It is a value that specifies the first week of the year. If this parameter is omitted, the Format function assumes that the week that contains January 1 is the first week of the year. This parameter can be one of the following values:

Constant Value Explanation
vbUseSystem 0 Uses the NLS API setting
vbFirstJan1 1 The week that contains January 1
vbFirstFourDays 2 The first week that has at least 4 days in the year
vbFirstFullWeek 3 The first full week of the year

Returns

The Format function returns a string value.

Applies To

The Format function can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example

Let's look at how to use the Format function with dates in MS Access:

Format (#17/04/2004#, "Short Date")
Result: '17/04/2004'

Format (#17/04/2004#, "Long Date")
Result: 'April 17, 2004'

Format (#17/04/2004#, "yyyy/mm/dd")
Result: '2004/04/17'

Example in VBA Code

The Format function can be used in VBA code in Microsoft Access.

For example:

Dim LValue As String

LValue = Format (Date, "yyyy/mm/dd")

In this example, the variable called LValue would now contain the date formatted as yyyy/mm/dd.

Example in SQL/Queries

You can also use the Format function in a query in Microsoft Access.

For example:

Microsoft Access

In this query, we have used the Format function as follows:

Expr1: Format([BirthDate],"yyyy/mm/dd")

This query will format the BirthDate field as "yyyy/mm/dd" display the results in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.

For example:

FormattedValue: Format([BirthDate],"yyyy/mm/dd")

The results would now be displayed in a column called FormattedValue.

The results of this query would look something like this:

Microsoft Access