什么是时间戳?
时间戳是指**格林尼治时间**1970年01月01日00时00分00秒(北京时间1970年01月01日时00分00秒)起至现在的总秒数。
时间戳=>指定格式的日期
# 如果不写第二个参数,默认格式是 yyyy-MM-dd HH:mm:ss
select unix_timestamp('20170101 13:20:30', 'yyyyMMdd HH:mm:ss') from test_table
时间=>日期
# 只能接受这种形式
select to_date('2017-01-01 13:20:30') from test_table
日期=>年/月/日/时/分/秒
# year(), month(), day(), hour(), minute(), second()
# week() 返回日期所在的星期数
select year('2017-01-01 13:20:30') from test_table
日期比较
# 返回结束日期减去开始日期的天数
# 语法:datediff(string enddate, string startdate)
select datediff('2017-01-31', '2017-01-1') from test_table
日期加减
# 语法:date_add(string startdate, int days)
select date_add('2017-01-01', 10) from test_table
select date_sub('2017-01-01', 10) from test_table