網(wǎng)站首頁 編程語言 正文
獲取當天0點的時間:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd 00:00:00');
執(zhí)行結(jié)果為:
2022-07-08 00:00:00 |
獲取當天0點的秒級時間戳:
select unix_timestamp(from_unixtime(unix_timestamp(),'yyyy-MM-dd 00:00:00'));
執(zhí)行結(jié)果:
1657209600 |
將時間作為條件,條件查詢
查詢創(chuàng)建時間(格式為yyyy-MM-dd HH:mm:ss)在前一天0點到今天0點之間的數(shù)據(jù)
select *?from table_t where created_time >?from_unixtime(unix_timestamp()-86400,'yyyy-MM-dd 00:00:00') and created_time <=?from_unixtime(unix_timestamp(),'yyyy-MM-dd 00:00:00')
若條件字段為時間戳使用時間戳,則同理使用unix_timestamp(from_unixtime(unix_timestamp(),'yyyy-MM-dd 00:00:00'))。
以上。
PS:
補充hive時間日期函數(shù),備忘
以下轉(zhuǎn)自hive時間日期函數(shù)總結(jié) - 簡書
-- 1、hive取得當前日期時間:
-- 1.1) 取得當前日期:
select current_date();
-- 1.2) 取得當前日期時間:
select current_timestamp();
-- 1.3) hive取得當前時間戳:
select unix_timestamp();
-- 1.4) 時間戳轉(zhuǎn)日期:
select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');
-- 1.5) 日期轉(zhuǎn)unix時間戳:
select to_nuix_timestamp('2017-01-01 12:12:12','yyyy-MM-dd HH:dd:ss');
-- 1.6) hive取得當前時間:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:dd:ss');
-- 2、hive自動計算其他日期(昨天,今天):
-- hive中日期加減函數(shù):date_add(start_date,num_days)
-- 2.1) 取得昨天日期:
select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
select date_format(date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
-- 2.2) 取得明天日期:
select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
-- 2.3)hive取得兩個日期之間差值(差值為天數(shù)):
-- datediff(date1,date2):date1大于date2,返回值為正,否則,返回值為負。
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-10));
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),10));
-- 2.4) 字符串轉(zhuǎn)時間(字符串必須為:yyyy-MM-dd格式)
select to_date('2017-01-01 12:12:12');
-- 2.5) 日期、時間戳、字符串類型格式化輸出標準時間格式:
select date_format(current_timestamp(),'yyyy-MM-dd HH:mm:ss');
select date_format(current_date(),'yyyyMMdd');
select date_format('2017-01-01','yyyy-MM-dd HH:mm:ss'); --字符串必須滿足yyyy-MM-dd格式
-- 2.6) utc時間轉(zhuǎn)換:
select from_utc_timestamp(current_timestamp(),8);
select to_utc_timestamp(current_timestamp(),8);
原文鏈接:https://blog.csdn.net/jian876601394/article/details/125681613
相關(guān)推薦
- 2023-12-14 如何統(tǒng)計一個字符在字符串中出現(xiàn)次數(shù)
- 2023-01-14 C++之eigen安裝與測試方式_C 語言
- 2022-08-04 Python中reduce函數(shù)詳解_python
- 2022-10-20 Flutter?StreamBuilder實現(xiàn)局部刷新實例詳解_Android
- 2022-01-18 django中ajax發(fā)送post請求報403錯誤csrf禁止,解決只需三步
- 2022-04-28 Python可視化學習之seaborn繪制線型回歸曲線_python
- 2022-06-29 利用python實現(xiàn)你說我猜游戲的完整實例_python
- 2022-10-27 C#利用Spire.Pdf包實現(xiàn)為PDF添加數(shù)字簽名_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支