栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

【presto 日期处理】

【presto 日期处理】

上篇文章【hive 日期处理】中我们介绍了hive的日期使用方法,现在我们对比看一下presto要如何实现

1、返回当周的周一
select date_format(date_trunc('week',current_date),'%Y-%m-%d')
2、返回当周周五
select date_add('day',4,cast(date_format(date_trunc('week',current_date),'%Y-%m-%d') as date))

3、日期加减(日、小时、分钟、秒)
select date_add('day',6,current_date); --参数可以设置为:'year','quarter','month','week','day','hour','minute','second'
4、时间差(日、小时、分钟、秒)
select date_diff('day', cast('2020-07-23 15:01:13' as timestamp), cast('2020-07-24 11:42:58' as timestamp)) --参数可以设置为:'year','quarter','month','week','day','hour','minute','second'

5、时间戳转化成时间
--10位时间戳
    select format_datetime(from_unixtime(1595487673),'yyyy-MM-dd HH:mm:ss')
--13位时间戳
    select format_datetime(from_unixtime(1595487673343/1000),'yyyy-MM-dd HH:mm:ss')

6、日期转化成时间戳
--10位时间戳
    select to_unixtime(cast('2020-07-23 15:01:13' as timestamp))
--13位时间戳
    select to_unixtime(cast('2020-07-23 15:01:13.343' as timestamp))*1000

详细内容请看我公众号~

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/707867.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号