Date and Time Formats
Date and time formats are both input and output formats. Like numeric formats, each input format generates a default output format, automatically expanded (if necessary) to accommodate display width. Internally, all date and time format values are stored as a number of seconds: date formats (e.g., DATE, ADATE, SDATE, DATETIME) are stored as the number of seconds since October 14, 1582; time formats (TIME, DTIME) are stored as a number of seconds that represents a time interval (e.g., 10:00:00 is stored internally as 36000, which is 60 seconds x 60 minutes x 10 hours).
- All date and time formats have a minimum input width, and some have a different minimum output. Wherever the input minimum width is less than the output minimum, the width is expanded automatically when displaying or printing values. However, when you specify output formats, you must allow enough space for displaying the date and time in the format you choose.
- Input data shorter than the specified width are correctly evaluated as long as all the necessary elements are present. For example, with the TIME format, 1:2, 01 2, and 01:02 are all correctly evaluated even though the minimum width is 5. However, if only one element (hours or minutes) is present, you must use a time function to aggregate or convert the data. See the topic Date and time functions for more information.
- If a date or time value cannot be completely displayed in the specified width, values are truncated in the output. For example, an input time value of 1:20:59 (1 hour, 20 minutes, 59 seconds) displayed with a width of 5 will generate an output value of 01:20, not 01:21. The truncation of output does not affect the numeric value stored in the working file.
The following table shows all available date and time formats, where w indicates the total number of columns and d (if present) indicates the number of decimal places for fractional seconds. The example shows the output format with the minimum width and default decimal positions (if applicable). The format allowed in the input data is much less restrictive. See the topic Input Data Specification for more information.
General form | Format type | Min w In | Min w Out | Max w | Max d | Example |
---|---|---|---|---|---|---|
dd-mmm-yy |
DATEw |
9 |
9 |
40 |
28-OCT-90 |
|
dd-mmm-yyyy |
DATEw |
10 |
11 |
28-OCT-1990 |
||
mm/dd/yy |
ADATEw |
8 |
8 |
40 |
10/28/90 |
|
mm/dd/yyyy |
ADATEw |
10 |
10 |
10/28/1990 |
||
dd.mm.yy |
EDATEw |
8 |
8 |
40 |
28.10.90 |
|
dd.mm.yyyy |
EDATEw |
10 |
10 |
28.10.1990 |
||
yyddd |
JDATEw |
5 |
5 |
40 |
90301 |
|
yyyyddd |
JDATEw |
7 |
7 |
1990301 |
||
yy/mm/dd |
SDATEw |
8 |
8 |
40 |
90/10/28 |
|
yyyy/mm/dd |
SDATEw |
10 |
10 |
1990/10/28 |
||
q Q yy |
QYRw |
4 |
6 |
40 |
4 Q 90 |
|
q Q yyyy |
QYRw |
6 |
8 |
4 Q 1990 |
||
mmm yy |
MOYRw |
6 |
6 |
40 |
OCT 90 |
|
mmm yyyy |
MOYRw |
8 |
8 |
OCT 1990 |
||
ww WK yy |
WKYRw |
6 |
8 |
40 |
43 WK 90 |
|
ww WK yyyy |
WKYRw |
8 |
10 |
43 WK 1990 |
||
(name of the day) |
WKDAYw |
2 |
2 |
40 |
SU |
|
(name of the month) |
MONTHw |
3 |
3 |
40 |
JAN |
|
hh:mm |
TIMEw |
5 |
5 |
40 |
01:02 |
|
hh:mm:ss.s |
TIMEw.d |
10 |
10 |
40 |
16 |
01:02:34.75 |
dd hh:mm |
DTIMEw |
1 |
1 |
40 |
20 08:03 |
|
dd hh:mm:ss.s |
DTIMEw.d |
13 |
13 |
40 |
16 |
20 08:03:00 |
dd-mmm-yyyy hh:mm |
DATETIMEw |
17 |
17 |
40 |
20-JUN-1990 08:03 |
|
dd-mmm-yyyy hh:mm:ss.s |
DATETIMEw.d |
22 |
22 |
40 |
16 |
20-JUN-1990 08:03:00 |
* All date and time formats produce sortable data. SDATE, a date format used in a number of Asian countries, can be sorted in its character form and is used as a sortable format by many programmers.