MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

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:

DataYearDays
Data 1201450
Data 22015100
Data 32016150
Data 42017200
Data 52018250

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:

DataYearDaysMAKEDATE_Value
Data 12014502014-02-19
Data 220151002015-04-10
Data 320161502016-05-29
Data 420172002017-07-19
Data 520182502018-09-07

❮ MySQL Functions