curtime函数 mysql

mysql中curtime函数有什么用

沐橙
355
2021-05-19 18:21:07
栏目: 云计算

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


mysql中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

0
看了该问题的人还看了