Date/Time Formats - Reading
Previous Topic  Next Topic 

You can control how Stat/Transfer reads dates and time.  In most cases, users will not need to change the default settings in order to read date and time variables.  However, if you do need to do so, you provide a general "scanning" input format in the Scan edit box, which is used when an ASCII file is opened for reading.  The input format given in Scan is used in the initial look at the file, which will determine variable types and also specific formats for dates, times, and date/time variables.  The default input format is constructed so that it will decipher a number of different date and time possibilities.


Note that if you are using a Schema file to describe your data, the date and time formats given there will override the formats set here.


The separate input formats for date, time and date/time variables are given in the Date:, Time:, and Date/Time: edit boxes.  These formats must match those given in the general scanning input format.  (The entries in these edit boxes are used when the data file is being used in a transfer and allow for much more efficient reading of the file.)


The input format strings given in the Scan:, Date:, Time:, and Date/Time: edit boxes are used to convert character strings to date/time variables.  The format strings are read from left to right. If a width is given explicitly for a particular variable, that will be used when reading the character string.  Otherwise, the width will be determined by the presence of delimiter characters.  Characters in the list below allow characters in a string to be skipped, if necessary.


If the entire input string is not matched by the format string or if the resulting time or date is not valid, the variable will be set to missing.


Each date and time part of the input format, as well as some special characters, have the form '%char' or  '%Xchar', where the modifier X is used to determine field widths.


The two different cases of '%Xchar' are:


%numberchar   When a number precedes the specification character, char, it specifies the field width to be used. The next number characters in the input string are scanned for the specified date or time.


%:delimchar   If there is a colon and any single character, delim, preceding the specification character, char, then the field to be read is taken to be all the characters up to but not including the given delimiter character, delim. The delimiter itself is not scanned or skipped by the format, and therefore must be entered explicitly in the input format or explicitly skipped. (Note that the modifier :delim need not be used routinely, since numeric and alpha formats will automatically stop reading when they reach a delimiter.)


The characters used to create the input formats are listed below.  Anything to be read from the input character string that is not in the list below, such as commas or other delimiters, must be given explicitly in the input format.  White space (spaces, tabs, carriage returns, and so on) is ignored in the input format string.



%c 

skip a single character (see also %w)


%Nc

skip N characters


%$c

skip the rest of the input string


%d

input day of the month


%H

input hour


%m

input month, as integer or as alpha string

(If it is an alpha string, case does not matter; any substring of a month that distinguishes it from the other months will be accepted.)


%M

input minute


%n

input milliseconds


%N

input milliseconds or tenths or hundredths of seconds

(If no field width is given and the input string has a field width of three, then input will be milliseconds. A field width of 1, either given explicitly or inferred from the input string, will cause input of 10ths of a second; a width of 2 will cause input of 100ths of a second.)


%p

input strings defining 'am' and 'pm'

(Matching is the same as for months.)


%S

input seconds


%w

skip a white space delimited word (see also %c)


%y

input year

(If less than 100, the century changeover year is used to determine the actual year.)


%Y

input year as found in the input string


%%,%[,%]

input the '%', '[', and ']' characters from the input string.


[...]

optional specification

(Text and specifications within the brackets will be read if  present in the input string, but need not be there.)


   

The default format for scanning times in text files is:


[%m[/]%d[/][,]%y] [%H:%M[:%S[.%N]][%p][[(]%3c[)]]]


which will recognize such diverse strings as:


   May 18 1945

   May 18, 1945

   5/18/45

   05/18/45 2:16 PM



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 '20', so that the changeover year from one century to another is 1920.  Thus the date 1/1/01 will be interpreted as January 1, 2001, while the date 1/1/31 will be interpreted as January 1, 1931.


If your data refer to dates earlier than 1920, 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.