The Date and Time data type can be formatted in a locale-sensitive manner. You can choose one of several predefined Date and Time formats, or type in a custom format string.
The following table shows predefined format property settings for the Date and Time data type:
Setting |
Locale |
Description |
General Date |
US (Default) England |
Example: 9/24/02 2:30:45 PM Example: 9/24/02 2:30 |
Long Date |
US |
Example: September 24, 2002 |
Medium Date |
US |
Example: Sep 24, 2002 |
Short Date |
US |
Example: 9/24/02 |
Long Time |
US |
Example: 2:15:30 PM EDT |
Medium Time |
US |
Example: 2:15:30 PM |
Short Time |
US |
Example: 2:15 PM |
To specify the time format, use a time pattern string. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:
Letter |
Date or Time |
Examples |
G |
Era designator |
AD |
y |
Year |
1996; 96 |
M |
Month in year |
July; Jul; 07 |
w |
Week in year |
27 |
W |
Week in month |
2 |
D |
Day in year |
189 |
d |
Day in month |
10 |
F |
Day of week in month |
2 |
E |
Day in week |
Tuesday; Tue |
a |
Am/pm marker |
PM |
H |
Hour in day (0-23) |
0 |
k |
Hour in day (1-24) |
24 |
K |
Hour in am/pm (0-11) |
0 |
h |
Hour in am/pm (1-12) |
12 |
m |
Minute in hour |
30 |
s |
Second in minute |
55 |
S |
Millisecond |
978 |
z |
Time zone |
Pacific Standard Time; PST; GMT-08:00 |
Z |
Time zone |
-0800 |
The count of pattern letters determines the format.
(Text): 4 or more pattern letters = use full form, less than 4 pattern letters = use short or abbreviated form if one exists.
(Number): the minimum number of digits. Shorter numbers are zero-padded to this amount. Year is handled specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.
(Text & Number): 3 or over, use text, otherwise use number. Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', '#', and '@' will appear in the resulting time text even if they are not embraced within single quotes.
Some examples using the US locale:
Date and Time Pattern |
Result |
yyyy.MM.dd G 'at' HH:mm:ss z |
2001.07.04 AD at 12:08:56 PDT |
EEE, MMM d, ''yy |
Wed, Jul 4, '01 |
h:mm a |
12:08 PM |
hh 'o''clock' a, zzzz |
12 o'clock PM, Pacific Daylight Time |
K:mm a, z |
0:08 PM, PDT |
yyyyy.MMMMM.dd GGG hh:mm aaa |
02001.July.04 AD 12:08 PM |
EEE, d MMM yyyy HH:mm:ss Z |
Wed, 4 Jul 2001 12:08:56 -0700 |
yyMMddHHmmssZ |
010704120856-0700 |
'Date Ordered: 'EEE, MMM dd, yy |
Date Ordered: Fri, Oct 31, 03 |