mysql——获取当前日期、时间的各种方式

1、当前时间的各种格式

 

 2、now()和sysdate()的区别

验证2.sql语句测试: 

mysql> select now(),sleep(3),now(); 

+---------------------+----------+---------------------+ 

| now()               | sleep(3) | now()               | 

+---------------------+----------+---------------------+ 

| 2011-01-21 11:25:45 |        0 | 2011-01-21 11:25:45 | 

+---------------------+----------+---------------------+ 

1 row in set (3.00 sec) 

评:now()函数,每次取语句开始的执行时间. 

mysql> select sysdate(),sleep(3),sysdate(); 

+---------------------+----------+---------------------+ 

| sysdate()           | sleep(3) | sysdate()           | 

+---------------------+----------+---------------------+ 

| 2011-01-21 11:26:44 |        0 | 2011-01-21 11:26:47 | 

+---------------------+----------+---------------------+ 

1 row in set (3.02 sec) 

评:sysdate() 每次会取实际的时间。

posted @ 2023-04-10 15:09  hushuer  阅读(245)  评论(0编辑  收藏  举报