MariaDB MAKEDATE() Function
In MariaDB, MAKEDATE()
is a built-in function that constructs a date base on the given year and the number of days in the year.
If you need to construct a time, use MAKETIME()
.
MariaDB MAKEDATE()
Syntax
This is the syntax of the MariaDB MAKEDATE()
function:
MAKEDATE(year, day_of_year)
Parameters
year
-
Required. A 4-digit year.
day_of_year
-
Required. The day of the year. Should be greater than
0
.
If you provide no parameters or the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'MAKEDATE'
.
Return value
The MariaDB MAKEDATE()
function creates a date based on the year and the day of the year and returns it.
If day_of_year
is equal to or less than 0
, the MAKEDATE()
function will return NULL
.
If the number of days in a year is exceeded day_of_year
, the MAKEDATE()
function returns a date with a future year.
MariaDB MAKEDATE()
Examples
Example 1
SELECT
MAKEDATE(2023, 1),
MAKEDATE(2023, 31),
MAKEDATE(2023, 100)\G
Output:
MAKEDATE(2023, 1): 2023-01-01
MAKEDATE(2023, 31): 2023-01-31
MAKEDATE(2023, 100): 2023-04-10
Example 2
If the number of days in a year is exceeded day_of_year
, the MAKEDATE()
function returns a date with a future year.
SELECT
MAKEDATE(2023, 366),
MAKEDATE(2023, 600);
Output:
+---------------------+---------------------+
| MAKEDATE(2023, 366) | MAKEDATE(2023, 600) |
+---------------------+---------------------+
| 2024-01-01 | 2024-08-22 |
+---------------------+---------------------+
Example 3
If day_of_year
is equal to or less than 0
, the MAKEDATE()
function will return NULL
.
example:
SELECT
MAKEDATE(2023, 0),
MAKEDATE(2023, -1);
Output:
+-------------------+--------------------+
| MAKEDATE(2023, 0) | MAKEDATE(2023, -1) |
+-------------------+--------------------+
| NULL | NULL |
+-------------------+--------------------+
Conclusion
In MariaDB, MAKEDATE()
is a built-in function that constructs a date base on the given year and the number of days in the year.