Date/Time Formats – Reading

 

Stat/Transfer version 16 introduces a new and much easier way of specifying formats or masks for reading dates and times.  These are similar to, but easier to use than those in Stata.  They are easier to use because the formats are implemented so they simply skip over non-date components and punctuation.  For instance, the date mask YMD can read all of the following dates:

 

Jan 1, 2022

January 01, 2022

1/1/2022

02/02/22

1-1-2022

January 20th 2022

 

Mask Element

Comments

Y

Year – this will read two or four digit years.  If two digits are found the “century crossover year (by default 30) be used to set the century component

M

Month – this will read one or two digit month numbers and also spelled-out month names and abbreviations.  The names and abbreviations, by default, are in English, but if you set the ASCII/Read option “Use localized Month Names”,  Stat/Transfer will use the names that are set in your computer’s locale

D

Day – the day of the month. 

h

Hour – 0 to 23 or 1 to 12 if AM/PM (or its local equivalent) is present.

m

Minutes  - 0 to 59

s

Seconds – 0 to 59.  Fractional seconds (tenths, hundreds and milliseconds) will be read if a decimal point is present.

 

Notes

Spaces are not significant – Y M D is equivalent to YMD.  The elements are read from left to right and compared to the input.  Spaces and punctuation, as well as extraneous characters are ignored in the input as well.

 

 

Examples

Input Date

Mask

January 1, 2022

MDY

11:01

hm or hms

11:01.22

hms

22:01.001

hms

11:30 PM

hm

01012022

MDY

01-02-2022

MDY

01-FEB-2022

DMY

2022-01-11T12:43

YMD hm

06Jan2021

DMY

6Jan2021

DMY

20210111

YMD

 

 

Century Changeover Year

When you are reading two-digit years, some may fall in the twenty-first century and some in the twentieth.  You can use this option to control how two digit years are read.  Any two-digit year less than the changeover year will have the first two digits of the complete four digit year set to 20.  Any year greater than or equal to the changeover year will have the first two digits set to 19.

 

The default for the option is '30', so that the changeover year from one century to another is 1930.  Thus the date 1/1/21 will be interpreted as January 1, 2021, while the date 1/132 will be interpreted as January 1, 1932.

 

If your data refer to dates earlier than 1930, such as birth dates, you will need to override the default behavior and specify a different changeover year.  If, for example, you specify '00', this would cause all two digit dates to be interpreted as years in the twentieth century.