hive 與mysql 日期操作

2021-09-26 13:46:09 字數 1212 閱讀 3056

日期操作

涉及函式:

date_format(date, format) 函式,mysql日期格式化函式date_format()

unix_timestamp() 函式

str_to_date(str, format) 函式

from_unixtime(unix_timestamp, format) 函式,mysql時間戳格式化函式from_unixtime

-- 時間轉換為字串

select date_format(日期字段,』%y-

%m-%d』)

as 『日期』 from test

#結果:2017-01-05

select unix_timestamp(

now())

;

select str_to_date(

'2016-01-02'

,'%y-%m-%d %h');

#結果:2017-01-02 00:00:00

select unix_timestamp(

'2016-01-02');

#結果:1451664000

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)

mysql 日期操作

今天 select from 表名 where to days 時間欄位名 to days now 昨天 select from 表名 where to days now to days 時間欄位名 1 本週 select from 表名 where yearweek date format 時間欄...

mysql日期操作

一 獲取當前日期時間 1.1 獲得當前日期 時間 date time 函式 now 1.2 獲取當前日期 時間 date time 函式 sysdate 注 二者類擬,不同在於now 在執行時就得到了,sysdate 執行時動態得到。2 獲取當前日期 curdate 與current date 等同...

十三 Hive中日期操作總結

1 獲取當前時間hive default select current date 2020 05 26hive default select current timestamp 2020 05 2616 03 09.0122 date format函式 日期格式化hive default selec...