hive 與mysql 日期操作

一、Hive

https://blog.csdn.net/hyfstyle/article/details/88567959

二、MySQL

2.1 日期格式化

涉及函數:
date_format(date, format) 函數,MySQL日期格式化函數date_format()
unix_timestamp() 函數
str_to_date(str, format) 函數
from_unixtime(unix_timestamp, format) 函數,MySQL時間戳格式化函數from_unixtime

2.1.1 時間轉換

  • 時間轉換爲字符串
-- 時間轉換爲字符串
select date_format(日期字段,%Y-%m-%d’) as ‘日期’ from test

#結果:2017-01-05  
  • 時間轉換爲時間戳
select unix_timestamp(now());

2.1.2 字符串轉換

  • 字符串轉換爲時間
select str_to_date('2016-01-02', '%Y-%m-%d %H'); 

#結果:2017-01-02 00:00:00 
  • 字符串轉時間戳
select unix_timestamp('2016-01-02');  
  
#結果:1451664000 

2.1.3 時間戳轉換

  • 時間戳轉時間
select from_unixtime(1451997924);  
  
#結果:2017-01-05 20:45:24 
  • 時間戳轉字符串
select from_unixtime(1451997924,'%Y-%d');  
  
# 結果:2017-01-05 20:45:24  

附件:日期格式

%Y 四位數字表示的年份
%y 兩位數字表示的年份
%m 兩位數字表示的月份( 01, 02, . . ., 12)
%c 數字表示的月份( 1, 2, . . ., 12)
%d 兩位數字表示月中的天數( 00, 01, . . ., 31)
%e 數字形式表示月中的天數( 1, 2, . . ., 31)
%H 兩位數字形式的小時,24 小時(00,01, . . ., 23)
%h, %I 兩位數字形式的小時,12 小時(01,02, . . ., 12)
%S, %s 兩位數字形式的秒( 00,01, . . ., 59)
%i 兩位數字形式的分( 00,01, . . ., 59)

日期操作

https://www.cnblogs.com/ggjucheng/p/3352280.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章