温馨提示×

sql中curtime函数怎么用

小新
350
2021-05-25 10:50:03
栏目: 云计算

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

mysqlselect 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

mysqlselect curdate();

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

curdate() |

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

2013-01-17 |

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

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

mysqlselect curtime(), sleep(5), curtime();

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

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

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

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

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

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

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

mysqlselect 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()时,有可能导致主库和从库执行时返回值不一样,导致主从数据库不一致。

其它函数格式显示:

mysqlselect now(), curdate(), sysdate(), curtime() \G;

*************************** 1row ***********************

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

curdate()2013-01-17

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

curtime()13:07:53

0