Previous Page | Next Page

Formats

Working with Dates and Times Using the ISO 8601 Basic and Extended Notations


ISO 8601 Formatting Symbols

The following list explains the formatting symbols that are used to notate the ISO 8601 dates, time, datetime, durations, and interval values:

n

specifies a number that represents the number of years, months, or days

P

indicates that the duration that follows is specified by the number of years, months, days, hours, minutes, and seconds

T

indicates that a time value follows. Any value with a time must begin with T.

Requirement: Time values that are read by the extended notation informats that begin with the characters E8601 must use an uppercase T.
W

indicates that the duration is specified in weeks.

Z

indicates that the time value is the time in Greenwich, England, or UTC time.

+|-

the + indicates the time zone offset to the east of Greenwich, England. The - indicates the time zone offset to the west of Greenwich, England.

yyyy

specifies a four-digit year

mm

as part of a date, specifies a two-digit month, 01 - 12

dd

specifies a two-digit day, 01 - 31

hh

specifies a two-digit hour, 00 - 24

mm

as part of a time, specifies a two-digit minute, 00 - 59

ss

specifies a two-digit second, 00 - 59

fff | ffffff

specifies an optional fraction of a second using the digits 0 - 9:

fff

use 1 - 3 digits for values read by the $N8601B informat and the $N8601E informat

ffffff

use 1 - 6 digits for informat other than the $N8601B informat and the $N8601E informat

Y

indicates that a year value proceeds this character in a duration

M

as part of a date, indicates that a month value proceeds this character in a duration

D

indicates that a day value proceeds this character in a duration

H

indicates that an hour value proceeds this character in a duration

M

as part of a time, indicates that a minute value proceeds this character in a duration

S

indicates that a seconds value proceeds this character in a duration


Writing ISO 8601 Date, Time, and Datetime Values

SAS uses the formats in the following table to write date, time, and datetime values in the ISO 8601 basic and extended notations from SAS date, time, and datetime values.

Formats for Writing ISO 8601 Dates, Times, and Datetimes
Date, Time, or Datetime ISO 8601 Notation Example Format
Basic Notations
Date yyyymmdd
20080915 B8601DAw.
Time hhmmssffffff
155300322348 B8601TMw.d
Time with time zone hhmmss+|-hhmm 155300+0500 B8601TZw.d

hhmmssZ 155300Z B8601TZw.d
Convert to local time with time zone hhmmss+|-hhmm 155300+0500 B8601LZw.d
Datetime yyyymmddThhmmssffffff 20080915T155300 B8601DTw.d
Datetime with timezone yyyymmddThhmmss+|-hhmm 20080915T155300+0500 B8601DZw.d

yyyymmddThhmmssZ 20080915T155300Z B8601DZw.d


Write the date from a datetime yyyymmdd
20080915 B8601DNw.
Extended Notations
Date yyyy-mm-dd
2008-09-15 E8601DAw.
Time hh:mm:ss.ffffff
15:53:00.322348 E8601TMw.d
Time with time zone hh:mm:ss.ffffff+|-hh:mm 15:53:00+05:00 E8601TZw.d
Convert to local time with time zone hh:mm:ss.ffffff+|-hh:mm 15:53:00+05:00 E8601LZw.d
Datetime yyyy-mm-ddThh:mm:ss.ffffff 2008-09-15T15:53:00 E8601DTw.d
Datetime with time zone yyyy-mm-ddThh:mm:ss.nnnnnn+|-hh:mm 2008-09-15T15:53:00+05:00 E8601DZw.d
Write the date from a datetime yyyy-mm-dd
2008-09-15 E8601DNw.

An asterisk ( * ) used in place of a date or time formatted value that is out-of-range.


Writing ISO 8601 Duration, Datetime, and Interval Values


Duration, Datetime, and Interval Formats

SAS writes duration, datetime, and interval values from character data using these formats:

Time Component ISO 8601 Notation Example Format
Duration - Basic Notation PyyyymmddThhmmssfff P20080915T155300 $N8601BA

-PyyyymmddThhmmssfff -P20080915T155300 $N8601BA
Duration - Extended Notation Pyyyy-mm-ddThh:mm:ss.fff P2008-09-15T15:53:00 $N8601EA

-Pyyyy-mm-ddThh:mm:ss.fff -P2008-09-15T15:53:00 $N8601EA
Duration - Basic and Extended Notation PnYnMnDTnHnMnS P2y10m14dT20h13m45s $N8601B

$N8601E


-PnYnMnDTnHnMnS -P2y10m14dT20h13m45s $N8601B

$N8601E


PnW (weeks) P6w $N8601B

$N8601E

Interval - Basic Notation yyyymmddThhmmssfff/yyyymmddThhmmssfff 20080915T155300/20101113T000000 $N8601BA

PnYnMnDTnHnMnS/yyyymmddThhmmssfff P2y10M14dT20h13m45s/20080915T155300 $N8601B

yyyymmddThhmmssfff/PnYnMnDTnHnMnS 20080915T155300/P2y10M14dT20h13m45s $N8601BA
Interval- Extended Notation yyyy-mm-ddThh:mm:ss.fff/yyyy-mm-ddThh:mm:ss.fff 2008-09-15T15:53:00/2010-11-13T00:00:00 $N8601EA

PnYnMnDTnHnMnS/yyyy-mm-ddThh:mm:ss.fff P2y10M14dT20h13m45s/2008-09-15T15:53:00 $N8601E

yyyy-mm-ddThh:mm:ss.fff/PnYnMnDTnHnMnS 2008-09-15T15:53:00/P2y10M14dT20h13m45s $N8601EA
Datetime-Basic Notation yyyymmddThhmmss.fff+|-hhmm 20080915T155300 $N8601BA

(all blank)
$N8601B

$N8601BA

$N8601E

$N8601EA

Datetime-Extended Notation yyyy-mm-ddThh:mm:ss.fff+|-hhmm 2008-09-15T15:53:00

+04:30

$N8601EA

(all blank)
$N8601B

$N8601BA

$N8601E

$N8601EA


Writing Omitted Components

An omitted component can be represented by a hyphen ( - ) or an x in the extended datetime form yyyy-mm-ddThh:mm:ss and in the extended duration form Pyyyy-mm-ddThh:mm:ss.

Omitted components in the durations form PnYnMnDTnHnMnS are dropped, they do not contain a hyphen or x. For example, P2mT4H.

The following formats write omitted components that use the hyphen and the x:

Format Datetime Form Duration Form Examples
$N8601H yyyy-mm-ddThh:mm:ss PnYnMnDTnHnMnS --09-15T15:-:53

P2Y2DT4H5M6S/--09-15T15:-:00

$N8601EH yyyy-mm-ddThh:mm:ss Pyyyy-mm-ddThh:mm:ss P000---02T02:55:20/2008---15T-:-:45
$N8601X yyyy-mm-ddThh:mm:ss PnYnMnDTnHnMnS P2Y2DT4H5M6S/x-09-15T15:x:00
$N8601EX yyyy-mm-ddThh:mm:ss Pyyyy-mm-ddThh:mm:ss P0003-x-02T02:55:20/2008-x-15Tx:x:45

Datetime values with omitted components that are formatted with either the $N8601B format or the $N8601BA format are formatted in the extended notation using the hyphen for omitted components to ensure accurate data. For example, when the month is an omitted component, the value 2008---15 is written and not 2008-15.

The extended notation with hyphens is also used in place of the basic notation if a duration is formatted by using the $N8601BA format. Using the same date, P2008---15 is written and not P2008-15.


Writing Truncated Duration, Datetime, and Interval Values

Duration, datetime, or interval values can be truncated when one or more lower order values is 0 or is not significant. When SAS writes a truncated value using the formats $N8601B, $N8601BA, $N8601E, and $N8601EA, the display of the value stops at the last non-missing component.

When you format a truncated value by using either the $N8601H format or the $N8601EH format, the lower order components are written with a hyphen. When you format a truncated value by using the $N8601X format or the $N8601EX format, the lower order components are written with an x.

The following examples show truncated values:

p00030202T1031

2008-09-15T15/2010-09-15T15:53

-p0003-03-03T-:-:-

P2y3m4dT5h6m

2008-09-xTx:x:x

2008


Normalizing Duration Components

When a value for a duration component is greater than the largest standard value for a component, SAS normalizes the component except when the duration component is a single component. The following table shows examples of normalized duration components:

Duration Extended Normalized Duration
p3y13m
p0004-01
pt24h24m65s
P----01T-:25:05
p3y13mT24h61m
P0004-01-01T01:01
p0004-13
p0005-01
p0003-02-61T15:61:61
P0003-04-01T16:02:01
p13m
P13M

If a component contains the largest value, such as 60 for minutes or seconds, SAS normalizes the value and replaces the value with a hyphen. For example, pT12:60:13 becomes PT13:-:13 .

Thirty days is used to normalize a month.

Dates and times in a datetime value that are greater than the standard value for the component are not normalized. They produce an error.


Fractions in Durations, Datetime, and Interval Values

Ending components can contain a fraction that consists of a period or a comma, followed by one to three digits. The following examples show the use of fractions in duration, datetime, and interval values:

200809.5

P2008-09-15T10.33

2008-09-15/P0003-03-03,333

Previous Page | Next Page | Top of Page