sql中curtime函数怎么用

552
2021/5/25 10:50:03
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

sql中curtime函数的用法:在sql中能够使用curtime函数可返回当前的时间,在SELECT语句中直接使用,使用语法为“SELECT CURTIME()”。


sql中curtime函数怎么用


具体使用示例:

SELECT 语句:


SELECT CURTIME() //返回当前时间


返回结果为:2021-5-18 12:45:34

相关知识点:

curtime和curtime区别

curtime是用来返回当前时间,而curtime则是返回当前时间,不包含年月日。

代码示例:

-- now() 返回当前日期和时间,格式如下:2013-01-17 10:57:13

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

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

| now() | sleep(5) | now() |

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

| 2013-01-17 10:57:13 | 0 | 2013-01-17 10:57:13 |

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

两个值相同,表示语句开始执行的时间。

-- curdate() 返回当前日期,格式如下:2013-01-17

mysql> select curdate();

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

| curdate() |

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

| 2013-01-17 |

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

-- curtime(), 返回当前时间,格式如下:12:49:26

mysql> select curtime(), sleep(5), curtime();

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

| curtime() | sleep(5) | curtime() |

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

| 12:49:26 | 0 | 12:49:26 |

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

两个值相同,都表示语句开始执行的时间。

-- sysdate() 返回当前日期和时间,格式:2013-01-17 13:02:40

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

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

| sysdate() | sleep(5) | sysdate() |

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

| 2013-01-17 13:02:40 | 0 | 2013-01-17 13:02:45 |

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

两个值不同,sysdate表示实时的系统时间。

sysdate() 和 now()的区别,一般在执行SQL语句时,都是用now();

因为使用sysdate()时,有可能导致主库和从库执行时返回值不一样,导致主从数据库不一致。

其它函数格式显示:

mysql> select now(), curdate(), sysdate(), curtime() \G;

*************************** 1. row ***********************

now(): 2013-01-17 13:07:53

curdate(): 2013-01-17

sysdate(): 2013-01-17 13:07:53

curtime(): 13:07:53


辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: set sql如何提高数据访问速度