MySQL时间函数

muzirigel 2019-06-28

1. now

now() 返回当前时间戳
2018-11-11 11:11:11
select now();

2. UNIX_TIMESTAMP

返回时间值
select UNIX_TIMESTAMP('2017-06-10 13:02:18');
--1497070938

3. FROM_UNIXTIME

返回时间戳
select FROM_UNIXTIME(1497070938, '%Y-%m-%d %H:%i:%S');
--2017-06-10 13:02:18
select FROM_UNIXTIME(1497070938);
--2017-06-10 13:02:18

4. curtime

返回当前时间
time(now()),current_time();
select curtime(),current_time(),time(now());

5. curdate

返回当前日期
date(now()),current_date();
select curdate(),current_date(),date(now());

6.datediff

日期差
select datediff('2008-08-08', '2008-08-01'); 
-- 7

相关推荐