| 返回類(lèi)型 | 示例 | 返回值 | 說(shuō)明 |
|---|---|---|---|
| date | to_date('2020-08-25 11:15:30') | 2020-08-25 | 字符串轉(zhuǎn)日期 |
| date | to_date('2020-08-25') | 2020-08-25 | 字符串轉(zhuǎn)日期 |
| string | from_unixtime(unix_timestamp('20200825','yyyyMMdd'),'yyyy-MM-dd') | 2020-08-25 | 字符串格式轉(zhuǎn)換 |
| string | from_unixtime(unix_timestamp('20200825','yyyyMMdd'),'yyyy-MM-dd') | 2020-08-25 | 字符串格式轉(zhuǎn)換 |
| string | from_unixtime(unix_timestamp('2020-08-25 23:15:25','yyyy-MM-dd HH:mm:ss'),'yyyyMMdd') | 20200825 | 字符串格式轉(zhuǎn)換 |
| string | from_unixtime(unix_timestamp('2020-08-25 23:15:25','yyyy-MM-dd HH:mm:ss'),'yyyyMMddHHmmss') | 20200825231525 | 字符串格式轉(zhuǎn)換 |
| date | cast('2020-08-25' as date) | 2020-08-25 | 字符串轉(zhuǎn)日期 |
| string | date_format('2020-08-25 11:15:25','yyyyMMddHHmmss') | 20200825111525 | 字符串日期格式轉(zhuǎn)換 |
| string | date_format('2020-08-25','yyyyMMdd') | 20200825 | 字符串日期格式轉(zhuǎn)換 |
| string | date_format('2020-08-25','yyyy') | 2020 | 字符串日期格式提取年份 |
| string | date_format('2020-08-25','MM') | 08 | 字符串日期格式提取月份 |
| string | date_format('2020-08-25','dd') | 25 | 字符串日期格式提取天 |
| int | datediff('2020-08-25','2020-08-20') | 5 | 日期想減得到相差天數(shù) |
| int | datediff('2020-08-25 11:00:00','2020-08-21 09:00:00') | 4 | 日期想減得到相差天數(shù)并忽略日期的其他部分 |
| date | current_date() | yyyy-MM-dd格式的當(dāng)前日期部分 | 獲取當(dāng)前系統(tǒng)日期部分 |
| timestamp | current_timestamp() | yyyy-MM-dd HH:mm:ss.ff例如2020-08-25 20:33:20.38格式的當(dāng)前時(shí)間 | 獲取系統(tǒng)當(dāng)前時(shí)間 |
| bigint | unix_timestamp('2020-08-25 11:30:01') | 1598326201 | 將 yyyy-MM-dd HH:mm:ss格式的字符串轉(zhuǎn)換為Unix 時(shí)間戳 (秒) |
Hive和Spark sql的各種日期轉(zhuǎn)換
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。