设为首页 加入收藏

TOP

Hive中日期与时间戳的转换教程
2017-12-14 14:32:21 】 浏览:329
Tags:Hive 日期 时间 转换 教程

什么是时间戳?

时间戳是指**格林尼治时间**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
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇mongodb导入导出数据、账号认证方.. 下一篇查询重复数据,某个字段允许指定..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目