In MariaDB, FROM_DAYS()
is a built-in date and time function that returns a date value based on a given number of days from the start of the standard calendar (0000-00-00).
You pass the number of days to the function when you call it.
The FROM_DAYS()
function is the converse of the TO_DAYS()
function.
Syntax
The syntax goes like this:
FROM_DAYS(N)
Where n
is the number of days to add to 0000-00-00.
Example
Here’s an example:
SELECT FROM_DAYS(743021);
Result:
+-------------------+ | FROM_DAYS(743021) | +-------------------+ | 2034-04-28 | +-------------------+
Invalid Arguments
When passed an invalid argument, FROM_DAYS()
returns 0000-00-00
with a warning:
SELECT FROM_DAYS('Dang');
Result:
+-------------------+ | FROM_DAYS('Dang') | +-------------------+ | 0000-00-00 | +-------------------+ 1 row in set, 1 warning (0.000 sec)
Check the warning:
SHOW WARNINGS;
Result:
+---------+------+-------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------+ | Warning | 1292 | Truncated incorrect INTEGER value: 'Dang' | +---------+------+-------------------------------------------+
Missing Argument
Calling FROM_DAYS()
with the wrong number of arguments, or without passing any arguments, results in an error:
SELECT FROM_DAYS();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'FROM_DAYS'
And another example:
SELECT FROM_DAYS( 1, 2 );
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'FROM_DAYS'
Pre-Gregorian Calendar
The FROM_DAYS()
function is not designed for use with dates before the advent of the Gregorian calendar (which was introduced in October 1582). Results will not be reliable since it doesn’t account for the lost days when the calendar changed from the Julian calendar.