Mysql 时间函数

获取时间

now() 获取时间 date + time

sysdate() 获取时间 date + time

sysdate 与 now 类似,但 now 在执行开始时就得到了值,sysdate 会动态获取,如下说明

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

+---------------------+----------+---------------------+
| now() | sleep(3) | now() |
+---------------------+----------+---------------------+
| 2008-08-08 22:28:21 | 0 | 2008-08-08 22:28:21 |
+---------------------+----------+---------------------+

current_timestamp() 获取当前时间戳

日期转换、时间转换

date_format(date,format)

time_format(time,format)

将日期转换为各种时间格式

str_to_date(str,format)

这是一个逆函数,将时间格式转换为时间

to_days(date), from_days(days)

这是一对逆函数,计算从 0000-00-00 的天数

time_to_sec(time), sec_to_time(seconds)

将时刻转换为秒与将秒转换为时刻