【MySQL】日期、时间相关
程序员文章站
2024-01-28 19:59:52
...
now()
获得当前日期+时间(date + time)
select now();
+---------------------+
| now() |
+---------------------+
| 2019-10-29 17:02:59 |
+---------------------+
1 row in set (0.00 sec)
sysdate()
获得当前日期+时间(date + time),与now()不同之处如下:
mysql> select sysdate(), sleep(3), sysdate();
+---------------------+----------+---------------------+
| sysdate() | sleep(3) | sysdate() |
+---------------------+----------+---------------------+
| 2019-10-29 17:05:19 | 0 | 2019-10-29 17:05:22 |
+---------------------+----------+---------------------+
1 row in set (3.07 sec)
mysql> select now(), sleep(3), now();
+---------------------+----------+---------------------+
| now() | sleep(3) | now() |
+---------------------+----------+---------------------+
| 2019-10-29 17:05:37 | 0 | 2019-10-29 17:05:37 |
+---------------------+----------+---------------------+
1 row in set (3.06 sec)
TO_DAYS(date)
给定日期,返回对应天数(年为0以来的天数)。
mysql> select TO_DAYS(20101029);
+-------------------+
| TO_DAYS(20101029) |
+-------------------+
| 734439 |
+-------------------+
1 row in set (0.01 sec)
上一篇: 【vbs】每30分钟提醒自己休息眼睛
下一篇: matlab 自带pca函数