当前位置:网站首页>How MySQL converts a date to a number

How MySQL converts a date to a number

2022-06-23 07:33:00 Yisu cloud

mysql How to convert a date to a number

This article introduces in detail “mysql How to convert a date to a number ”, Detailed content , The steps are clear , The details are handled properly , Hope this article “mysql How to convert a date to a number ” The article can help you solve your doubts , Let's follow Xiaobian's ideas and go deeper slowly , Let's learn new knowledge together .

2 A way to turn a date into a number :1、 Use TO_DAYS() function , You can convert the specified date value to an integer value representing the number of days , grammar “TO_DAYS( Specify date value )”.2、 Use TIME_TO_SEC() function , You can convert the specified date time value to an integer value representing the number of seconds , grammar “TIME_TO_SEC( Specify the date time value )”.

The operating environment of this tutorial :windows7 System 、mysql8 edition 、Dell G3 The computer .

mysql To convert a date into a number 2 Methods

1、 Use TO_DAYS() function

TO_DAYS() Function returns the date and year 0( date "0000-00-00") Days between .

namely : Give a date , Return a day ( Years for 0 Days since ).

Example :

select to_days('2022-01-08');

mysql How to convert a date to a number

2、 Use TIME_TO_SEC() function

TIME_TO_SEC(time) Function returns the parameter time Time value converted to seconds , Change the formula to “ Hours ×3600+ minute ×60+ second ”.

SELECT TIME_TO_SEC('2022-01-08 15:15:15');

mysql How to convert a date to a number

As can be seen from the execution results , According to the formula “15×3600+15×60+25” Result seconds 54915.

Read here , This article “mysql How to convert a date to a number ” The article has been introduced , If you want to master the knowledge points of this article, you need to practice and use it yourself to understand , If you want to know more about this article , Welcome to the Yisu cloud industry information channel .

原网站

版权声明
本文为[Yisu cloud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230500131013.html