2 ways to convert dates into numbers: 1. Use the TO_DAYS() function to convert the specified date value into an integer value representing the number of days, the syntax is "TO_DAYS (specified date value)". 2. Use the TIME_TO_SEC() function to convert the specified date and time value into an integer value representing the number of seconds. The syntax is "TIME_TO_SEC (specified date and time value)".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
Mysql 2 ways to convert dates into numbers
##1. Use the TO_DAYS() function
TO_DAYS() function returns the number of days between date and year 0 (date "0000-00-00"). That is: given a date, return a number of days (the number of days since the year is 0). Example:select to_days('2022-01-08');
2. Use the TIME_TO_SEC() function
TIME_TO_SEC (time) The function returns the time value converted from the parameter time into seconds. The conversion formula is "hour × 3600 minutes × 60 seconds".
SELECT TIME_TO_SEC('2022-01-08 15:15:15');
mysql video tutorial]
The above is the detailed content of How to convert date to number in mysql. For more information, please follow other related articles on the PHP Chinese website!