TIMESTAMP
An item of type TIMESTAMP is a series of one to twenty single-byte numeric digits that reflect a specific moment. The meaning of each digit is determined by the mask that you specify when declaring the item.
The following characters are available, in order, when you specify the mask:
- yyyy
- Four digits that represent the year. The range is 0000 to 9999.
- mm or MM
- Two digits that represent the month. The range is 01 to 12.
- dd
- Two digits that represent the day. The range is 01 to 31.
- hh
- Two digits that represent the hour. The range is 00 to 24.
- mm
- Two digits that represent the minute. The range is 00 to 59.
- ss
- Two digits that represent the second. The range is 00 to 59.
- f
- Zero to six digits that each represent a fraction of seconds; the first represents tenths, the second represents hundreds, and so on.
The default mask is yyyymmddhhmmss.
The difference between month (mm) and minutes (mm) is determined by context; mm is assumed to be minutes if it is immediately preceded by hh or followed by ss or if it is specified as the only type of character. MM always represents the month.
When you interact with DB2 (directly or by way of JDBC) , specify every component from year (yyyy) through seconds (ss). In other contexts, the following is true:
- You can have zero characters of a given kind at the beginning or end of a mask, but cannot skip intermediate characters.
- Valid masks include these:
yyyymmddhhmmss yyyy mmss- The following masks are invalid because intermediate characters are missing:
// NOT valid ddmmssffffff hhssff
The internal hexadecimal representation of an example value is as follows if the default mask (yyyymmddhhmmss) is in effect and if the item is on a host environment which uses EBCDIC:
// 8:05:10 o'clock on 12 January 2005 F2 F0 F0 F5 F0 F1 F1 F2 F0 F8 F0 F5 F1 F0The internal hexadecimal representation of an example value is as follows if the default mask (yyyymmddhhmmss) is in effect and if the item is on a workstation environment like Windows 2000, which uses ASCII:
// 8:05:10 o'clock on 12 January 2005 32 30 30 35 30 31 31 32 30 38 30 35 31 30An item of type TIMESTAMP can be compared with (or assigned to or from) an item of type TIMESTAMP or an item of type CHAR. However, an error occurs at development time if you assign a value that is not valid. An example is as follows:
// NOT valid because February 30 is not a valid date myTS timestamp("yyyymmdd"); myTS = "20050230";If characters at the beginning of a full mask are missing (for example, if the mask is "dd"), EGL assumes that the higher-level characters ("yyyymm", in this case) represent the current moment, in accordance with the machine clock. The following statements cause a run-time error in February:
// NOT valid because February 30 is not a date myTS timestamp("dd"); myTS = "30";Finally, an item of type TIMESTAMP can receive data from or provide data to a relational database.
Related reference
Assignments
Date and time (system words)
Datetime expressions
Logical expressions
Primitive types