1. 日期函数unix时间转日期函数:from_unixtime,语法为from_unixtime(bigint unixtime, stringformat)
select from_unixtime('1323308943','yyyyMMdd')
--20111208
2. 获取unixtime:current_timestamp()
select current_timestamp(from_unixtime())
3. 获取当前日期
select current_date()
4. 日期相减得到天数差:datediff(enddate,startdate)
5. 日期加减:date_add(date,add_days), date_sub(date,sub_days)
6. 转成日期:
select to_date('2018-02-27 10:03:01') ;
--2018-02-27
7
--当月最后一天
select last_day('2018-02-27 10:03:01');
--2018-02-28
--当月第一天
select trunc(current_date,'MM') as day;
--2020-11-01
--当年第一天
select trunc(current_date,'YY') as day;
--2020-01-01
--next_day,返回当前时间的下一个星期几所对应的日期
select next_day('2018-02-27 10:03:01', 'TU');
<