企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
TO_DAYS(date) 给定一个日期,返回一个天数(年为0以来的天数)。 ~~~ mysql> SELECT TO_DAYS(950501); +---------------------------------------------------------+ | TO_DAYS(950501) | +---------------------------------------------------------+ | 728779 | +---------------------------------------------------------+ 1 row in set (0.00 sec) ~~~ ~~~ mysql> SELECT TO_DAYS('2009-05-18'); +-----------------------+ | TO_DAYS('2009-05-18') | +-----------------------+ | 733910 | +-----------------------+ 1 row in set (0.03 sec) ~~~ 查询今天的数据: ~~~ SELECT * FROM 表名 WHERE TO_DAYS(日期时间字段名) = TO_DAYS(now()); ~~~ * * * * * [TO_DAYS](https://www.w3resource.com/mysql/date-and-time-functions/mysql-to_days-function.php) #### TO_DAYS(date) 返回日期date是西元0年至今多少天(不计算1582年以前) ~~~ mysql> select TO_DAYS(950501);   -> 728779 mysql> select TO_DAYS('1997-10-07');   -> 729669 ~~~