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, and MTIME) 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.

Table 1. Date and time formats
General form Format type Min w In Min w Out Max w Max d Example

dd-mmm-yy

DATEw

6

9

40

 

28-OCT-90

dd-mmm-yyyy

DATEw

8

11

   

28-OCT-1990

mm/dd/yy

ADATEw

6

8

40

 

10/28/90

mm/dd/yyyy

ADATEw

8

10

   

10/28/1990

dd.mm.yy

EDATEw

6

8

40

 

28.10.90

dd.mm.yyyy

EDATEw

8

10

   

28.10.1990

yyddd

JDATEw

5

5

40

 

90301

yyyyddd

JDATEw

7

7

   

1990301

yy/mm/dd

SDATEw

6

8

40

 

90/10/28

yyyy/mm/dd

SDATEw

8

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

4

8

40

 

43 WK 90

ww WK yyyy

WKYRw

6

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

4

5

40

 

01:02

hh:mm:ss.s

TIMEw.d

8

10

40

16

01:02:34.75

hh:mm:ss

TIMEw

8

8

40

 

11:50:30

mm:ss

MTIMEw

4

5

40

 

02:34

mm:ss.s

MTIMEw.d

6

7

40

16

02:34.75

ddd hh:mm

DTIMEw

1

1

40

 

20 08:03

ddd hh:mm:ss

DTIMEw

12

23

40

 

113 04:20:18

dd-mmm-yyyy hh:mm

DATETIMEw

17

17

40

 

20-JUN-1990 08:03

dd-mmm-yyyy hh:mm:ss.s

DATETIMEw.d

20

20

40

5

20-JUN-1990 08:03:00

dd-mmm-yyyy hh:mm:ss

DATETIMEw

20

20

40

 

10-Dec-1982 10:19:59

yyyy-mm-dd hh:mm

YMDHMSw

12

16

40

 

1990-06-20 08:03

yyyy-mm-dd hh:mm:ss

YMDHMS

19

19

40

 

1987-02-04 21:13:49

yyyy-mm-dd hh:mm:ss.s

YMDHMSw.d

16

21

40

5

1990-06-20 08:03:00.0

* 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.