Datetime Functions: DB2
DB2 implements the following special registers to return datetime information:
CURRENT DATEorCURRENT_DATEReturns the current date on the server.
CURRENT TIMEorCURRENT_TIMEReturns the current time on the server.
CURRENT TIMESTAMPorCURRENT_TIMESTAMPReturns the current date and time as a timestamp.
CURRENT TIMEZONEorCURRENT_TIMEZONEReturns the current time zone as a decimal number representing the time zone offset—in hours, minutes, and seconds—from UTC. The first two digits are the hours, the second two digits are the minutes, and the last two digits are the seconds.
DB2 also supports labeled durations. For example:
CURRENT_DATE + 1 YEARS - 3 MONTHS + 10 DAYS
Valid labels are YEAR, YEARS, MONTH, MONTHS, DAY, DAYS, HOUR, HOURS, MINUTE, MINUTES, SECOND, SECONDS, MICROSECOND, and MICROSECONDS.
Note
DB2 9.7 and higher now support many of the same functions as Oracle, notably: ROUND, TRUNC, ADD_MONTHS, LAST_DAY, NEXT_DAY, and MONTHS_BETWEEN. See Datetime Functions: Oracle for details.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access