1、获取当前时间的秒值
select unix_timestamp();
2、获取当前时间
select from_unixtime(unix_timestamp());
3、获取当前时间年月日
select to_date(from_unixtime(unix_timestamp()));
select current_date();
4、时间加减天
select date_add(current_date(),3);
select date_sub(current_date(),3);
5、trunc函数
SELECT trunc('2009-02-12', 'MM');MM只能是大写,如果小写,返回null。
SELECT trunc('2009-02-12', 'mm');
6、两个日期相差多少天
select datediff(current_date(),trunc(current_date(),'MM'));
select datediff(trunc(current_date(),'MM'),current_date());
select datediff(current_date(),current_date());