Format

<< Click to Display Table of Contents >>

Navigation:  Date / Time functions >

Format

Description

Returns a String containing an expression formatted according to instructions contained in a format expression.

Syntax

Format(expression[, format])

 

Parameters

Part

Type

Description

expression

Date

Required. Any valid date expression.

format

String

Optional. Any named or user defined format expression.

Predefined Named Date/Time formats.
The following table identifies the predefined date and time format names:

Format Name

Description

General Date

Displays a date and/or time. Date display is determined by your application's current culture value.

Long Date

Display a date according to your system's long date format.

Medium Date

Display a date using the medium date format appropriate for the language version of the host application.

Short Date

Display a date using your system's short date format.

Long Time

Display a time using your system's long time format; includes hours, minutes, seconds.

Medium Time

Display time in 12-hour format using hours and minutes and the AM/PM designator.

Short Time

Display a time using the 24-hour format, for example, 17:45.

User-Defined Date/Time Formats.

Descriptions preceded by an asterisk: They are differences with the Format function used in VBA (Visual Basic for Applications).
The following table identifies characters you can use to create user-defined date/time formats:

Format Name

Description

d

Display the day as a number without a leading zero (1 – 31).

dd

Display the day as a number with a leading zero (01 – 31).

ddd

Display the day as an abbreviation (Sun – Sat).

dddd

Display the day as a full name (Sunday – Saturday).

M

*Display the month as a number without a leading zero (1 – 12).

MM

*Display the month as a number with a leading zero (01 – 12).

MMM

*Display the month as an abbreviation (Jan – Dec).

MMMM

*Display the month as a full month name (January – December).

y

Year represented only by the last digit.

yy

Year represented only by the last two digits. A leading zero is added for single-digit years.

yyyy

Year represented by a full four or five digits, depending on the calendar used.

h

*Hours without leading zeros for single-digit hours (12-hour clock).

hh

*Hours with leading zeros for single-digit hours (12-hour clock).

H

*Hours without leading zeros for single-digit hours (24-hour clock).

HH

*Hours with leading zeros for single-digit hours (24-hour clock).

m

*Minutes without leading zeros for single-digit minutes.

mm

*Minutes with leading zeros for single-digit minutes.

s

*Seconds without leading zeros for single-digit seconds.

ss

*Seconds with leading zeros for single-digit seconds.

Example

Dim MyTime As Date

Dim MyDate As Date

Dim MyStr As String

 

MyTime = #17:04:23#

MyDate = #January 27, 1993#

 

' Returns current system time in the system-defined long time format.

MyStr = Format(Now, "Long Time")

 

' Returns current system date in the system-defined long date format.

MyStr = Format(Now, "Long Date")

 

MyStr = Format(MyTime, "h:m:s")            ' Returns "17:4:23".

MyStr = Format(MyDate, "dddd, MMM d yyyy") ' Returns "Wednesday,

                                          ' Jan 27 1993".