INTERVAL
An item of type INTERVAL is a series of one to twenty-one single-byte numeric digits that reflect an interval, which is the numeric difference between two points in time. The meaning of each digit is determined by the mask that you specify when declaring the item.
An interval can be positive (as when 1980 is subtracted from 2005) or negative (as when 2005 is subtracted from 1980), and at the beginning of the item is an extra byte that is not reflected in the mask. If an item of type INTERVAL is in a record, account for that extra byte when calculating the length of the record as well as the length of the superior item, if any.
You can specify a mask that is in either of two formats:
- Month span, which can include years and months
- Second span, which can include days, hours, minutes, seconds, and fractions of seconds
In either case, each character in the mask represents a digit. In the month-span format, for example, the set of y's indicate how many years are in the item. If you only need three digits to represent the number of years, specify yyy in the mask. If you need the maximum number of digits (nine) to represent the number of years, specify yyyyyyyyy.
In a given mask, the first character may be used as many as nine times (unless otherwise stated); but the number of each subsequent kind of character is restricted further.
For a mask that is in month-span format, the following characters are available, in order:
- y
- Zero to nine digits that represent the number of years in the interval.
- m or M
- Zero to nine digits that represent the number of months in the interval. If m or M is not the first character in the mask, only two digits are allowed, at most.
The default mask is yyyymm.
For a mask that is in second-span format, the following characters are available, in order:
- d
- Zero to nine digits that represent the number of days in the interval.
- h
- Zero to nine digits that represent the number of hours in the interval. If h is not the first character in the mask, only two digits are allowed, at most.
- m
- Zero to nine digits that represent the number of minutes in the interval. If m is not the first character in the mask, only two digits are allowed, at most.
- s
- Zero to nine digits that represent the number of seconds in the interval. If s is not the first character in the mask, only two digits are allowed, at most.
- f
- Zero to six digits that each represent a fraction of seconds; the first represents tenths, the second represents hundreds, and so on. Even when f is the first character in the mask, only six digits are allowed, at most.
Although you can have zero characters of a given kind at the beginning or end of a mask, you cannot skip intermediate characters. Valid masks include these:
yyyyyymm yyyyyy mm ddhhmmssffffff hhmmssff mmss hhmmThe following masks, however, are invalid because intermediate characters are missing:
// NOT valid ddmmssffffff hhssffThe internal hexadecimal representation of an example value is as follows if the default mask (yyyymm) is in effect and if the item is on a host environment which uses EBCDIC:
// 100 years, 2 months; the 4E means the value is positive 4E F0 F1 F0 F0 F0 F2 // 100 years, 2 months; the 60 means the value is negative 60 F0 F1 F0 F0 F0 F2The internal hexadecimal representation of an example value is as follows if the default mask (yyyymm) is in effect and if the item is on a workstation environment like Windows 2000, which uses ASCII:
// 100 years, 2 months; the 2B means the value is positive 2B 30 31 30 30 30 32 // 100 years, 2 months; the 2D means the value is negative 2D 30 31 30 30 30 32An item of type INTERVAL is strongly typed, so you cannot compare an item of this type with an item of any other type; nor can you assign an item of any other type to or from an item of this type.
Finally, an item of type INTERVAL cannot receive data from or provide data to a relational database.
Related reference
Date and time (system words)
Datetime expressions
Primitive types