Mysql To_days Function

MySQL: TO_DAYS Function

This tutorial explains how to use the MySQL TO_DAYS function with syntax and examples.


The MySQL TO_DAYS function converts a date into numeric days.


The syntax for the TO_DAYS function in MySQL is:

TO_DAYS( date )

Parameters or Arguments


The date to convert to numeric days.


  • The TO_DAYS function is to be used only with dates within the Gregorian calendar.
  • The TO_DAYS function will return NULL, if date is '0000-00-00'.
  • See also the FROM_DAYS function which is the reverse of the TO_DAYS function.

Applies To

The TO_DAYS function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23


Let's look at some MySQL TO_DAYS function examples and explore how to use the TO_DAYS function in MySQL.

For example:

mysql> SELECT TO_DAYS('2014-02-17');
Output: 735646

mysql> SELECT TO_DAYS('14-02-17');
Output: 735646

mysql> SELECT TO_DAYS('2014-02-18');
Output: 735647

mysql> SELECT TO_DAYS('2014-02-19 05:30:00');
Output: 735648

mysql> SELECT TO_DAYS('0000-01-01');
Output: 1

mysql> SELECT TO_DAYS('0000-00-00');
Output: NULL