In this section: |
The functions described in this section operate on fields in date-time format (sometimes called H format).
However, you can also provide a date as a character string using the macro DT, followed by a character string in parentheses, presenting date and time. Date components are separated by slashes '/'; time components by colons ':'.
Alternatively, the day can be given as a natural day, like 2004 March 31, in parentheses. Either the date or time component can be omitted. For example, the date-time format argument can be expressed as DT(2004/03/11 13:24:25.99) or DT(March 11 2004).
The following is another example that creates a timestamp representing the current date and time. The system variables &YYMD and &TOD are used to obtain the current date and time, respectively:
-SET &MYSTAMP = &YYMD | ' ' | EDIT(&TOD,'99:$99:$99') ;
Today's date (&YYMD) is concatenated with the time of day (&TOD). The EDIT function is used to change the dots (.) in the time of day variable to colons (:).
The following request uses the DT macro on the alphanumeric date and time variable &MYSTAMP:
TABLE FILE CAR
PRINT CAR NOPRINT
COMPUTE DTCUR/HYYMDS = DT(&MYSTAMP);
IF RECORDLIMIT IS 1;
END
In this section: |
The DATEFORMAT parameter specifies the order of the date components for certain types of date-time values. The WEEKFIRST parameter specifies the first day of the week. The DTSTRICT parameter determines the extent to which date-time values are checked for validity.
The DATEFORMAT parameter specifies the order of the date components (month/day/year) when date-time values are entered in the formatted string and translated string formats . It makes the input format of a value independent of the format of the variable to which it is being assigned.
The WEEKFIRST parameter specifies a day of the week as the start of the week. This is used in week computations by the HADD, HDIFF, HNAME, HPART, and HYYWD functions. It is also used by the DTADD, DTDIFF, DTRUNC, and DTPART functions. The default values are different for these functions, as described in How to Set a Day as the Start of the Week. The WEEKFIRST parameter does not change the day of the month that corresponds to each day of the week, but only specifies which day is considered the start of the week.
The HPART, DTPART, HYYWD, and HNAME subroutines can extract a week number from a date-time value. To determine a week number, they can use different definitions. For example, ISO 8601 standard week numbering defines the first week of the year as the first week in January with four or more days. Any preceding days in January belong to week 52 or 53 of the preceding year. The ISO standard also establishes Monday as the first day of the week.
You specify which type of week numbering to use by setting the WEEKFIRST parameter, as described in How to Set a Day as the Start of the Week.
Since the week number returned by HNAME, DTPART, and HPART functions can be in the current year or the year preceding or following, the week number by itself may not be useful. The function HYYWD returns both the year and the week for a given date-time value.
SET WEEKFIRST = value
where:
Can be:
Week numbering using these values establishes the first week in January with seven days as week number 1. Preceding days in January belong to the last week of the previous year. All weeks have seven days.
Note: ISO is a synonym for ISO2.
Week numbering using these values establishes the first week in January with at least four days as week number 1. Preceding days in January belong to the last week of the previous year. All weeks have seven days.
Note: STD without a digit is equivalent to STD1.
Week numbering using these values is as follows. Week number 1 begins on January 1 and ends on the day preceding the first day of the week. For example, for STD1, the first week ends on the first Saturday of the year. The first and last week may have fewer than seven days.
The following designates Sunday as the start of the week, usinf non-standard week numbering:
SET WEEKFIRST = 1
Strict processing checks date-time values when they are input by an end user, read from a transaction file, displayed, or returned by a subroutine to ensure that they represent a valid date and time. For example, a numeric month must be between 1 and 12, and the day must be within the number of days for the specified month.
SET DTSTRICT = {ON|OFF}
where:
Invokes strict processing. ON is the default value.
Strict processing checks date-time values when they are input by an end user, read from a transaction file, displayed, or returned by a subroutine to ensure that they represent a valid date and time. For example, a numeric month must be between 1 and 12, and the day must be within the number of days for the specified month.
If DTSTRICT is ON and the result would be an invalid date-time value, the function returns the value zero (0).
Does not invoke strict processing. Date-time components can have any value within the constraint of the number of decimal digits allowed in the field. For example, if the field is a two-digit month, the value can be 12 or 99, but not 115.
Reference: |
Date-time functions may operate on a component of a date-time value. This topic lists the valid component names and abbreviations for use with these functions.
The following component names, valid abbreviations, and values are supported as arguments for the date-time functions that require them:
Component Name |
Abbreviation |
Valid Values |
---|---|---|
year |
yy |
0001-9999 |
quarter |
|
1-4 |
month |
mm |
1-12 or a month name, depending on the function. |
day-of-year |
dy |
1-366 |
day or day-of-month |
dd |
1-31 (The two component names are equivalent.) |
week |
wk |
1-53 |
weekday |
dw |
1-7 (Sunday-Saturday) |
hour |
hh |
0-23 |
minute |
mi |
0-59 |
second |
ss |
0-59 |
millisecond |
ms |
0-999 |
microsecond |
mc |
0-999999 |
nanosecond |
ns |
0-999999999 |
Note:
iWay Software |