Db2 Date Functions

This section introduces you to some common Db2 date functions that help you manipulate date and time data effectively.

FunctionDescription
ADD_DAYSReturns a datetime value that represents the first argument plus a specified number of days.
ADD_HOURSReturns a timestamp value that represents the first argument plus a specified number of hours.
ADD_MINUTESReturns a timestamp value that represents the first argument plus a specified number of minutes.
ADD_MONTHSReturns a datetime value that represents expression plus a specified number of months.
ADD_SECONDSReturns a timestamp value that represents the first argument plus a specified number of seconds and fractional seconds.
ADD_YEARSReturns a datetime value that represents the first argument plus a specified number of years.
AGEReturns a numeric value that specifies the number of full years, full months, and full days between the current timestamp and the argument.
DATE_PARTReturns portion of a datetime based on its argument.
DATE_TRUNCReturns a timestamp expression rounded to the specified unit.
DAYReturns the day part of a value.
DAYNAMEReturns a character string containing the name of the day (for example, Friday) for the day portion of expression, based on locale-name or the value of the special register CURRENT LOCALE LC_TIME.
DAYOFMONTHReturns an integer between 1 and 31 that represents the day of the month.
DAYOFWEEKReturns the day of the week in the first argument as an integer value. The integer value is in the range 1-7, where 1 represents the first day of the week, as specified in the second argument.
DAYOFWEEK_ISOReturns the day of the week from a value, where 1 is Monday and 7 is Sunday.
DAYOFYEARReturns the day of the year from a value.
DAYSReturns an integer representation of a date.
DAYS_BETWEENReturns the number of full days between the specified arguments.
DAYS_TO_END_OF_MONTHReturns the number of days to the end of the month.
EXTRACTReturns a portion of a date or timestamp based on the arguments.
FIRST_DAYReturns a date or timestamp that represents the first day of the month of the argument.
FROM_UTC_TIMESTAMPReturns a TIMESTAMP that is converted from Coordinated Universal Time to the timezone that is specified by the timezone string.
HOURReturns the hour part of a value.
HOURS_BETWEENReturns the number of full hours between the specified arguments.
JULIAN_DAYReturns an integer value representing the number of days from January 1, 4712 B.C. to the date specified in the argument.
LAST_DAYReturns a datetime value that represents the last day of the month of the argument.
MICROSECONDReturns the microsecond part of a value.
MIDNIGHT_SECONDSReturns an integer value representing the number of seconds between midnight and a specified time value.
MINUTEReturns the minute part of a value.
MINUTES_BETWEENReturns the number of full minutes between the specified arguments.
MONTHReturns the month part of a value.
MONTHNAMEReturns a character string containing the name of the month (for example, January) for the month portion of expression, based on locale-name or the value of the special register CURRENT LOCALE LC_TIME.
MONTHS_BETWEENReturns an estimate of the number of months between expression1 and expression2.
NEXT_DAYReturns a datetime value that represents the first weekday, named by string-expression, that is later than the date inexpression.
NEXT_MONTHReturns the first day of the next month after the specified date.
NEXT_QUARTERReturns the first day of the next quarter after the specified date.
NEXT_WEEKReturns the first day of the next week after the specified date.
NEXT_YEARReturns the first day of the next year after the specified date.
NOWReturns a timestamp based on when the SQL statement is executed at the current server.
QUARTERReturns an integer that represents the quarter of the year in which a date resides.
ROUNDReturns a datetime value, rounded to the unit specified by format-string.
ROUND_TIMESTAMPReturns a timestamp that is the expression rounded to the unit specified by the format-string.
SECONDReturns the seconds part of a value.
SECONDS_BETWEENReturns the number of full seconds between the specified arguments.
THIS_MONTHReturns the first day of the month in the specified date.
THIS_QUARTERReturns the first day of the quarter in the specified date.
THIS_WEEKReturns the first day of the week in the specified date.
THIS_YEARReturns the first day of the year in the specified date.
TIMESTAMP_FORMATReturns a timestamp from a character string (argument1) that has been interpreted using a format template (argument2).
TIMESTAMP_ISOReturns a timestamp value based on a date, time, or timestamp argument. If the argument is a date, it inserts zero for all the time elements. If the argument is a time, it inserts the value of CURRENT DATE for the date elements, and zero for the fractional time element.
TIMESTAMPDIFFReturns an estimated number of intervals of type argument1, based on the difference between two timestamps. The second argument is the result of subtracting two timestamp types and converting the result to CHAR.
TO_CHARReturns a CHARACTER representation of a timestamp.
TO_DATEReturns a timestamp from a character string.
TO_NCHARReturns a national character representation of an input expression that has been formatted using a character template.
TO_TIMESTAMPReturns a timestamp that is based on the interpretation of the input string using the specified format.
TO_UTC_TIMESTAMPReturns a TIMESTAMP that is converted from Coordinated Universal Time to the timezone specified by the timezone string.
TRUNCATE or TRUNCReturns a datetime value, truncated to the unit specified by format-string.
TRUNC_TIMESTAMPReturns a timestamp that is the expression truncated to the unit specified by the format-string.
VARCHAR_FORMATReturns a CHARACTER representation of a timestamp (argument1), formatted according to a template (argument2).
WEEKReturns the week of the year from a value, where the week starts with Sunday.
WEEK_ISOReturns the week of the year from a value, where the week starts with Monday.
WEEKS_BETWEENReturns the number of full weeks between the specified arguments.
YEARReturns the year part of a value.
YEARS_BETWEENReturns the number of full years between the specified arguments.
YMD_BETWEENReturns a numeric value that specifies the number of full years, full months, and full days between two datetime values.
Was this tutorial helpful ?