MySQL: DAYOFYEAR Function
This MySQL tutorial explains how to use the MySQL DAYOFYEAR function with syntax and examples.
Description
The MySQL DAYOFYEAR function returns day of the year for a date value.
Syntax
The syntax for the DAYOFYEAR function in MySQL is:
DAYOFYEAR( date_value )
Parameters or Arguments
- date_value
- The date or datetime value from which to extract the day of year.
Note
- The DAYOFYEAR function returns the day of the year (a number from 1 to 366) given a date value.
Applies To
The DAYOFYEAR function can be used in the following versions of MySQL:
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let's look at some MySQL DAYOFYEAR function examples and explore how to use the DAYOFYEAR function in MySQL.
For example:
mysql> SELECT DAYOFYEAR('2014-01-01'); Result: 1 mysql> SELECT DAYOFYEAR('2014-02-28'); Result: 59 mysql> SELECT DAYOFYEAR('2014-12-31'); Result: 365
This last DAYOFYEAR example would display the day of the year for the current system date (current system date is returned by the CURDATE function).
mysql> SELECT DAYOFYEAR(CURDATE());
Advertisements