DAY,MONTH,and YEAR
The DAY, MONTH, and YEAR functions take a date expression as input, and returns the day, month, and year, respectively, from the date expression.
Syntax
DAY (date_expression)
MONTH (date_expression)
YEAR (date_expression)
Remarks
• | The date_expression cannot be an empty string. |
• | Leading zeroes in a date or month are ignored in the output. |
• | If the input is NULL, the output is also NULL. |
Name and Format |
Data Type of date_expression |
Output Type |
Output Value |
DAY |
DATE, TIMESTAMP |
INTEGER |
Between 1 and 31. |
NULL |
NULL |
NULL |
|
MONTH |
DATE, TIMESTAMP |
INTEGER |
Between 1 and 12. |
NULL |
NULL |
NULL |
|
YEAR |
DATE, TIMESTAMP |
INTEGER |
Between 1 and 9999. |
NULL |
NULL |
NULL |
Example
SELECT DAY (orders.OrderDate) OrderDate,
MONTH (orders.OrderDate) OrderMonth,
YEAR (orders.OrderDate) OrderYear
FROM /shared/examples/ds_orders/orders orders