Datetime Functions: DB2
DB2 implements the following special registers to return datetime information:
CURRENT DATE
orCURRENT_DATE
Returns the current date on the server.
CURRENT TIME
orCURRENT_TIME
Returns the current time on the server.
CURRENT TIMESTAMP
orCURRENT_TIMESTAMP
Returns the current date and time as a timestamp.
CURRENT TIMEZONE
orCURRENT_TIMEZONE
Returns 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.
Get SQL Pocket Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.