DAYOFYEAR returns the day of the year, as an integer from 1 to 366, where 1 is January 1.

Syntax

DAYOFYEAR(expression)

Arguments

expression: a DATE, TIMESTAMP, or non-LONG VARCHAR string value that is properly formatted to represent a DATE or TIMESTAMP.

Returns

  • An INTEGER representing the day, between 1 and 366. Returns NULL when expression is NULL.

Examples

SELECT orderDate, DAYOFYEAR(orderDate) AS orderDateDay FROM MYSQL.inventory.cust;

VALUES DAYOFYEAR(CAST('2012-06-20' AS TIMESTAMP))
-- Returns 172

VALUES DAYOFYEAR(CAST('2012-06-03' AS TIMESTAMP))
-- Returns 155