DAYOFYEAR() MySQL Function Examples

DAYOFYEAR() MySQL Function Examples

In this tutorial, we are going to discuss briefly about the MySQL DAYOFYEAR function with its syntax and more useful examples. We will take different examples of DAYOFYEAR function with MySQL like CURDATE, Now etc.

When we fetch the records from the database, if we want to return the day of year of any date. In that case, we can use the DAYOFYEAR function.


In MySQL, the DAYOFYEAR() is used to return the day of the year from a date. It will returns always a numeric value between 1 and 366

The DAYOFYEAR () function is very simple to use with MySQL queries. Let’s see the syntax and examples below.


Basic Syntax of DAYOFYEAR() function is:


The date here is the date value that you want the day of the year from which it was returned.


Now let’s take an example to explain.

SELECT DAYOFYEAR('2020-06-18') AS 'Result';


| Result |
|    170 |


Let’s take another example for explain with different date.

SELECT DAYOFYEAR('2018-02-01') AS 'Result';


| Result |
|    32  |

Example-3 With Database Query

Next database example, when we get records from the database at that time we want to remove the day of the year from create_at(or any date column of your table)

 created_at AS create_date,
 DAYOFYEAR(created_at) AS day_of_year
 FROM users
 WHERE id= 112;


| create_date         | day_of_year |
| 2010-08-23 10:33:39 |       235    |

Example-4 Using Current Date/Time

Let’s take a new example, extract day of year from the current date and time (which is now returned using the () function).



| NOW()               | DAYOFYEAR(NOW())   |
| 2019-07-12 18:30:44 |        193         |

Example-4 With MySQL CURDATE() Function

Let’s take a next example of using CURDATE () function. If you want to know more about CURDATE () function click here.



| 2019-07-12 |             193       |


Here, You have learned how to use mysql DAYOFYEAR() function with various examples.

You may like

  1. LAST_DAY MySQL Function Examples
  2. MySQL weekday function with example
  3. MySQL CURRENT TIMESTAMP Function Examples
  4. Get month name from date in mysql
  5. mysql get first day of the current month
  6. mysql last day of previous month
  7. Get month number from month name in mysql
  8. mysql get day of week number from date
  9. Mysql Get Data Of Current Date, Week, Month, YEAR
  10. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql

If you have any questions or thoughts to share, use the comment form below to reach us.


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *