mysql时间函数之current_date,curdate,current_time,curtime,now用法

语法

CURRENT_DATE, CURRENT_DATE()

CURRENT_DATE and CURRENT_DATE() are synonyms for CURDATE().

CURRENT_DATE和CURRENT_DATE()是CURDATE()的同义词。


CURDATE()

Returns the current date as a value in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in a string or numeric context.

根据函数是在字符串还是数字上下文中使用,以“YYYY-MM-DD”或YYYYMMDD格式的值返回当前日期。


CURRENT_TIME, CURRENT_TIME([fsp])

CURRENT_TIME and CURRENT_TIME() are synonyms for CURTIME().

CURRENT_TIME和CURRENT_TIME()是CURTIME()的同义词。


CURTIME([fsp])

Returns the current time as a value in ‘HH:MM:SS’ or HHMMSS format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.

If the fsp argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits.

根据函数是在字符串还是数字上下文中使用,以“HH:MM:SS”或HHMMSS格式的值返回当前时间。 该值以当前时区表示。
如果给出的fsp参数指定从0到6的分秒精度,则返回值包含该许多数字的小数部分。


NOW([fsp])

Returns the current date and time as a value in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.

If the fsp argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits.

根据函数是在字符串还是数字上下文中使用,将当前日期和时间返回为’YYYY-MM-DD HH:MM:SS’或YYYYMMDDHHMMSS格式的值。 该值以当前时区表示。
如果给出的fsp参数指定从0到6的分数秒精度,则返回值包含该许多数字的小数部分。



实例

SELECT current_date(), curdate(), curdate() + 0;      # '2018-03-09' '2018-03-09'  20180309
SELECT current_time(), curtime(), curtime() + 0;      # 16:49:41  16:49:41  164941
SELECT current_time(2), curtime(2), curtime(2) + 0;   # 16:50:50  16:50:50  165050.01

SELECT now(), now(3), now(6);
# 2018-03-09 16:53:51       2018-03-09 16:53:51.163        2018-03-09 16:53:51.163791

你可能感兴趣的:(【mysql】)