DAYOFYEAR
DAYOFYEAR is a date function in SQL. It returns the day of the year for a date. The returned value is in the range from 1 to 366, inclusive.
DAYOFYEAR(date)
- date: This parameter represents the date value from which the day of the year will be extracted. The date must be a valid one in the format ‘YYYY-MM-DD’ or ‘YYYYMMDD’. This function will return null if the input date is invalid.
Example
Output
Explanation
The DAYOFYEAR
function in this example returns the day of the year from the date ‘2022-05-22’. The output is ‘142’, meaning ‘2022-05-22’ is the 142nd day of the year 2022.
DAYOFYEAR( date )
- date: Represents the date from which the day of the year is to be calculated. This parameter should be a valid expression in SQL Server and can be of date, time, datetime or smalldatetime type. The DAYOFYEAR function will return a number between 1 and 366 that corresponds to the day in the year, with 1 representing January 1st.
Example
Output
Explanation
The DAYOFYEAR function in the example returns the day of the year for a given date. In the provided code, the date ‘2022-10-12’ is used, and the function returns ‘285’, indicating that it’s the 285th day of the year.
DAYOFYEAR(date): NUMBER
- date: The date from which the day of the year is to be derived. The format accepted is date or timestamp. This parameter allows the retrieval of the numerical day of the year from a specified date, with values ranging from 1 to 366.
Oracle does not support the DAYOFYEAR function directly, but it can be emulated using the TO_CHAR function and ‘DDD’ format model which returns the day of the year. Here’s the documentation formatted as requested:
Example
Output
Explanation
The example provided performs a query to obtain the day of the year from the current date. The output 057
means that the current date is the 57th day of the year.