MariaDB TO_DAYS() Function
In MariaDB, TO_DAYS() is a built-in function that returns the number of days since 0 year (0000-00-00) for a given date.
The TO_DAYS() function is the opposite of the FROM_DAYS() function.
MariaDB TO_DAYS() Syntax
This is the syntax of the MariaDB TO_DAYS() function:
TO_DAYS(date)
Parameters
date-
Required. a date value.
If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'TO_DAYS'.
Return value
The MariaDB TO_DAYS() function returns the number of days since the 0 year for the specified date.
If the argument is NULL, the TO_DAYS() function will return NULL.
MariaDB TO_DAYS() Examples
This statement returns the number of days from the 0 year of 2023-01-01:
SELECT TO_DAYS('2023-01-01');
Output:
+-----------------------+
| TO_DAYS('2023-01-01') |
+-----------------------+
| 738886 |
+-----------------------+If you want to return the number of days since from the 0 year of today, you can use the NOW() function:
SELECT
NOW(),
TO_DAYS(NOW());
Output:
+---------------------+----------------+
| NOW() | TO_DAYS(NOW()) |
+---------------------+----------------+
| 2023-01-12 14:17:16 | 738897 |
+---------------------+----------------+Conclusion
In MariaDB, TO_DAYS() is a built-in function that returns the number of days since the 0 year (0000-00-00) for a given date.