MySQL MAKEDATE() Function
The MySQL MAKEDATE() function returns a date based on specified year and number_of_days values. If the number_of_days is less than 1, this function will return NULL.
Syntax
MAKEDATE(year, number_of_days)
Parameters
year |
Required. Specify the 4-digit year used to create the date. |
number_of_days |
Required. Specify the day of the year (greater than 0) used to create the date. |
Return Value
Returns the date based on specified year and number_of_days values.
Example 1:
The example below shows the usage of MAKEDATE() function.
mysql> SELECT MAKEDATE(2018, 100); Result: '2018-04-10' mysql> SELECT MAKEDATE(2018, 200); Result: '2018-07-19' mysql> SELECT MAKEDATE(2018, 365); Result: '2018-12-31' mysql> SELECT MAKEDATE(2018, 366); Result: '2019-01-01' mysql> SELECT MAKEDATE(2018, 400); Result: '2019-02-04' mysql> SELECT MAKEDATE(2018, 0); Result: NULL
Example 2:
Consider a database table called Sample with the following records:
Data | Year | Days |
---|---|---|
Data 1 | 2014 | 50 |
Data 2 | 2015 | 100 |
Data 3 | 2016 | 150 |
Data 4 | 2017 | 200 |
Data 5 | 2018 | 250 |
To create a date based on values of column Year and column Days, the following query can be used:
SELECT *, MAKEDATE(Year, Days) AS MAKEDATE_Value FROM Sample;
This will produce the result as shown below:
Data | Year | Days | MAKEDATE_Value |
---|---|---|---|
Data 1 | 2014 | 50 | 2014-02-19 |
Data 2 | 2015 | 100 | 2015-04-10 |
Data 3 | 2016 | 150 | 2016-05-29 |
Data 4 | 2017 | 200 | 2017-07-19 |
Data 5 | 2018 | 250 | 2018-09-07 |
❮ MySQL Functions