How MAKEDATE() Works in MariaDB

In MariaDB, MAKEDATE() is a built-in date and time function that returns a date, based on the year and day of year provided as arguments.

Syntax

The syntax goes like this:

MAKEDATE(year,dayofyear)

Example

Here’s an example:

SELECT MAKEDATE(2030, 10);

Result:

+--------------------+
| MAKEDATE(2030, 10) |
+--------------------+
| 2030-01-10         |
+--------------------+

And another one:

SELECT MAKEDATE(2030, 100);

Result:

+---------------------+
| MAKEDATE(2030, 100) |
+---------------------+
| 2030-04-10          |
+---------------------+

Return a Date in a Future Year

If the second (day of year) argument is greater than the number of days in the year, then the resulting date is a future year.

Example:

SELECT
    MAKEDATE(2030, 366),
    MAKEDATE(2030, 700),
    MAKEDATE(2030, 7000);

Result:

+---------------------+---------------------+----------------------+
| MAKEDATE(2030, 366) | MAKEDATE(2030, 700) | MAKEDATE(2030, 7000) |
+---------------------+---------------------+----------------------+
| 2031-01-01          | 2031-12-01          | 2049-03-01           |
+---------------------+---------------------+----------------------+

Zero Days

The second (day of year) argument must be greater than 0 or the result is null.

Example:

SELECT
    MAKEDATE(2030, 366),
    MAKEDATE(2030, 700),
    MAKEDATE(2030, 7000);

Result:

+---------------------+---------------------+----------------------+
| MAKEDATE(2030, 366) | MAKEDATE(2030, 700) | MAKEDATE(2030, 7000) |
+---------------------+---------------------+----------------------+
| 2031-01-01          | 2031-12-01          | 2049-03-01           |
+---------------------+---------------------+----------------------+

Missing Argument

Calling MAKEDATE() with the wrong number of arguments, or without passing any arguments, results in an error:

SELECT MAKEDATE();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'MAKEDATE'

And another example:

SELECT MAKEDATE( 2020, 10, 20 );

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'MAKEDATE'

Make a Time

Also see MAKETIME() for constructing a time value from its hours, minutes, and seconds.