In this guide, we will explain how to use the MySQL TO_DAYS function with syntax and examples.
Description
The MySQL TO_DAYS function converts a date into numeric days.
Syntax
The syntax for the TO_DAYS function in MySQL is:
TO_DAYS( date )
Parameters or Arguments
date
The date to convert to numeric days.
Note
- 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 :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some TO_DAYS function examples and explore how to use the TO_DAYS function.
For example:
mysql> SELECT TO_DAYS('2014-02-17'); Result: 735646 mysql> SELECT TO_DAYS('14-02-17'); Result: 735646 mysql> SELECT TO_DAYS('2014-02-18'); Result: 735647 mysql> SELECT TO_DAYS('2014-02-19 05:30:00'); Result: 735648 mysql> SELECT TO_DAYS('0000-01-01'); Result: 1 mysql> SELECT TO_DAYS('0000-00-00'); Result: NULL
Next Topic : Click Here
Pingback: MySQL: TIMESTAMP Function | Adglob Infosystem Pvt Ltd