The following articles mainly describe the date and time functions of common DB2 functions. If you are a popular topic of Date and Time Functions of common DB2 functions. The following article is meaningful to you. The following is a detailed description of the relevant content.
Article category: Database keywords: db2, functions, date and time
Common DB2 functions: DATE Functions
Syntax: DATE (ARG)
The DATE function returns a DATE in a DATE, timestamp, DATE string, or timestamp string.
SQL code
Eg:
Select date ('1970-06-12 16.24.18.121212 ') FROM TEST
Eg:
Select date ('1970-06-12 16.24.18.121212 ') FROM TEST
Common DB2 functions: TIME Functions
Syntax: TIME (ARG)
The TIME function returns the TIME of a TIME, timestamp, or timestamp string parameter.
SQL code
Eg:
Select time ('2017-06-12 16.24.18.121212 ') FROM TEST
Eg:
Select time ('2017-06-12 16.24.18.121212 ') FROM TEST
Common DB2 functions: TIMESTAMP Functions
Syntax: TIMESTAMP (EXPRES1 [, EXPRES2])
The TIMESTAMP function returns the TIMESTAMP of one or two parameters.
SQL code
Eg:
Select timestamp ('2017-06-12 16.24.18.121212 ') FROM TEST
Eg:
Select timestamp ('2017-06-12 16.24.18.121212 ') FROM TEST
Note: if there is only one parameter, this parameter must be a timestamp or a timestamp string. If there are two parameters, the first parameter must be a date or date string, the second parameter must be a time or timestamp string.
DB2 common functions: YEAR Functions
Syntax: YEAR (ARG)
The YEAR function returns the YEAR of a date, timestamp, date string, and timestamp string.
SQL code
Eg:
Select year ('1970-06-12 ') FROM TEST
Eg:
Select year ('1970-06-12 ') FROM TEST
MONTH Function
Syntax: MONTH (ARG)
DB2 common functions: the MONTH function returns the MONTH portion of a date, timestamp, date string, and timestamp string.
SQL code
Eg:
Select month ('2014-06-12 ') FROM TEST
Eg:
Select month ('2014-06-12 ') FROM TEST
QUARTER Functions
Syntax: QUARTER (ARG)
The QUARTER function returns the QUARTER of a date, timestamp, date string, and timestamp string.
SQL code
Eg:
Select quarter (current date) FROM TEST
Eg:
Select quarter (current date) FROM TEST
WEEK Function
Syntax: WEEK (ARG)
The WEEK function returns the WEEK part of a date, timestamp, date string, and timestamp string.
SQL code
Eg:
Select week (current date) FROM TEST
Eg:
Select week (current date) FROM TEST
Common DB2 functions: DAY functions
Syntax: DAY (ARG)
The DAY function returns the DAY part of a date, timestamp, date string, and timestamp string.
SQL code
Eg:
Select day (current date) FROM TEST
Eg:
Select day (current date) FROM TEST
HOUR Function
Syntax: HOUR (ARG)
The HOUR function returns the HOUR part of a date, timestamp, date string, and timestamp string.