最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Hive常用日期格式轉(zhuǎn)換語(yǔ)法

 更新時(shí)間:2022年06月23日 11:59:04   作者:周小董  
這篇文章主要為大家介紹了Hive常用日期格式轉(zhuǎn)換語(yǔ)法的操作示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

獲取當(dāng)前時(shí)間

  • 獲取當(dāng)前時(shí)間戳
select unix_timestamp()
  • 把時(shí)間戳轉(zhuǎn)為正常的日期
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss')
select from_unixtime(unix_timestamp(),'yyyy-MM-dd') 
  • 業(yè)務(wù)中有時(shí)存放的是包含毫秒的整數(shù),需要先轉(zhuǎn)換為秒
select from_unixtime(cast(create_time/1000 as bigint),'yyyyMMdd') as dt
  • 返回當(dāng)天三種方式
SELECT CURRENT_DATE;   --2017-06-15
select current_date();   -- 2021-10-22

SELECT current_timestamp; --返回時(shí)分秒
--2018-06-18 10:37:53.278
SELECT from_unixtime(unix_timestamp());
--2017-06-15 19:55:04

日期格式轉(zhuǎn)換

  • 日期格式轉(zhuǎn)換 yyyyMMdd—>yyyy-MM-dd
select from_unixtime(unix_timestamp('20211022','yyyyMMdd'),"yyyy-MM-dd");
2021-10-22
  • 固定日期轉(zhuǎn)換成時(shí)間戳
select unix_timestamp('2016-08-16','yyyy-MM-dd') --1471276800
select unix_timestamp('20160816','yyyyMMdd') --1471276800
select unix_timestamp('2016-08-16T10:02:41Z', "yyyy-MM-dd'T'HH:mm:ss'Z'") --1471312961
16/Mar/2017:12:25:01 +0800 轉(zhuǎn)成正常格式(yyyy-MM-dd hh:mm:ss)
select from_unixtime(to_unix_timestamp('16/Mar/2017:12:25:01 +0800', 'dd/MMM/yyy:HH:mm:ss Z'))
  • 時(shí)間戳轉(zhuǎn)換程固定日期
select from_unixtime(1471276800,'yyyy-MM-dd') --2016-08-16
select from_unixtime(1471276800,'yyyyMMdd') --20160816
select from_unixtime(1471312961) --    2016-08-16 10:02:41
select from_unixtime( unix_timestamp('20160816','yyyyMMdd'),'yyyy-MM-dd')  --2016-08-16
select date_format('2016-08-16','yyyyMMdd') --20160816
  • 字符串強(qiáng)制轉(zhuǎn)換,獲取日期
select to_date('2016-08-16 10:03:01') --2016-08-16
類似sql 中的date
  • 截取日期部分
select substr('2021-10-22 17:34:56',1,10)
2021-10-22

select date_format('2021-10-22 17:34:56','yyyy-MM-dd')
2021-10-22

返回日期中的年,月,日,時(shí),分,秒,當(dāng)前的周數(shù)

  • 返回日期中的年
select year('2016-08-16 10:03:01') --2016
  • 返回日期中的月
select month('2016-08-16 10:03:01') --8
  • 返回日期中的日
select day('2016-08-16 10:03:01') --16
  • 返回日期中的時(shí)
select hour('2016-08-16 10:03:01') --10
  • 返回日期中的分
select minute('2016-08-16 10:03:01') --3
  • 返回日期中的秒
select second('2016-08-16 10:03:01') --1
  • 返回日期在當(dāng)前的周數(shù)
select weekofyear('2016-08-16 10:03:01') --33

計(jì)算日期差值

  • 返回結(jié)束日期減去開始日期的天數(shù)
select datediff('2016-08-16','2016-08-11') 
  • 返回開始日期startdate增加days天后的日期
select date_add('2016-08-16',10)
  • 返回開始日期startdate減少days天后的日期
select date_sub('2016-08-16',10)

前一日/昨日
select date_sub(current_date(),1);
2021-10-21

最近一個(gè)月/30天
select date_sub(current_date(),30);
2021-09-22
  • 前一日12點(diǎn)/昨日12點(diǎn)
select concat(date_format(date_sub(current_date(),1),'yyyy-MM-dd'),' ','12');
2021-10-21 12

返回當(dāng)月或當(dāng)年的第一天

  • 返回當(dāng)月的第一天
select trunc('2016-08-16','MM') --2016-08-01

select date_format(to_date(trunc(current_date(),'MM')),"yyyy-MM-dd");
2021-10-01
  • 返回當(dāng)年的第一天
select trunc('2016-08-16','YEAR') --2016-01-01

參考匯總

固定日期轉(zhuǎn)換成時(shí)間戳
select unix_timestamp('2016-08-16','yyyy-MM-dd') --1471276800
select unix_timestamp('20160816','yyyyMMdd') --1471276800
select unix_timestamp('2016-08-16T10:02:41Z', "yyyy-MM-dd'T'HH:mm:ss'Z'") --1471312961
16/Mar/2017:12:25:01 +0800 轉(zhuǎn)成正常格式(yyyy-MM-dd hh:mm:ss)
select from_unixtime(to_unix_timestamp('16/Mar/2017:12:25:01 +0800', 'dd/MMM/yyy:HH:mm:ss Z'))
時(shí)間戳轉(zhuǎn)換程固定日期
select from_unixtime(1471276800,'yyyy-MM-dd') --2016-08-16
select from_unixtime(1471276800,'yyyyMMdd') --20160816
select from_unixtime(1471312961) --    2016-08-16 10:02:41
select from_unixtime( unix_timestamp('20160816','yyyyMMdd'),'yyyy-MM-dd')  --2016-08-16
select date_format('2016-08-16','yyyyMMdd') --20160816
返回日期時(shí)間字段中的日期部分
select to_date('2016-08-16 10:03:01') --2016-08-16
類似sql 中的date
取當(dāng)前時(shí)間
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss')
select from_unixtime(unix_timestamp(),'yyyy-MM-dd') 
返回日期中的年
select year('2016-08-16 10:03:01') --2016
返回日期中的月
select month('2016-08-16 10:03:01') --8
返回日期中的日
select day('2016-08-16 10:03:01') --16
返回日期中的時(shí)
select hour('2016-08-16 10:03:01') --10
返回日期中的分
select minute('2016-08-16 10:03:01') --3
返回日期中的秒
select second('2016-08-16 10:03:01') --1
返回日期在當(dāng)前的周數(shù)
select weekofyear('2016-08-16 10:03:01') --33
返回結(jié)束日期減去開始日期的天數(shù)
select datediff('2016-08-16','2016-08-11') 
返回開始日期startdate增加days天后的日期
select date_add('2016-08-16',10)
返回開始日期startdate減少days天后的日期
select date_sub('2016-08-16',10)
返回當(dāng)天三種方式
SELECT CURRENT_DATE;
--2017-06-15
SELECT CURRENT_TIMESTAMP;--返回時(shí)分秒
--2017-06-15 19:54:44
SELECT from_unixtime(unix_timestamp());
--2017-06-15 19:55:04
返回當(dāng)前時(shí)間戳
Select current_timestamp--2018-06-18 10:37:53.278
返回當(dāng)月的第一天
select trunc('2016-08-16','MM') --2016-08-01
返回當(dāng)年的第一天
select trunc('2016-08-16','YEAR') --2016-01-01

 參考鏈接:

Hive日期格式轉(zhuǎn)換方法總結(jié)

以上就是Hive常用日期格式轉(zhuǎn)換語(yǔ)法的詳細(xì)內(nèi)容,更多關(guān)于Hive日期格式轉(zhuǎn)換的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

右玉县| 六枝特区| 本溪| 略阳县| 桃园市| 昭觉县| 宝丰县| 陇西县| 鄂托克旗| 丹巴县| 吉林市| 河池市| 山西省| 西平县| 西吉县| 横峰县| 民和| 辽宁省| 和硕县| 建平县| 朝阳县| 宁国市| 来凤县| 资阳市| 托里县| 宁都县| 上蔡县| 瑞金市| 洞头县| 大港区| 和林格尔县| 交城县| 新闻| 临沧市| 普定县| 桂东县| 明水县| 枣强县| 华阴市| 保靖县| 东台市|