Hive 中 时间戳,字符串转换

13位时间戳装换为日期格式的字符串

select from_unixtime( cast(1597651229344/1000 as int),'yyyy-MM-dd HH:mm:ss')

 时间字符串比较大小

Mysql

使用函数:STR_TO_DATE(str, format)

使用示例:select * from h_hotelcontext where now() between STR_TO_DATE(Start_time,'%Y-%m-%d %H:%i:%s') and STR_TO_DATE(End_time,'%Y-%m-%d %H:%i:%s');

使用注意点:format的格式为%Y-%m-%d %H:%i:%s ,中间的分隔符也需要跟你传入的字符串格式对上

参考链接:https://blog.csdn.net/weixin_30426065/article/details/97320937?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

HIVE

没用过类似的转化函数,想去找来着,但是突然发现就按比较字符串的逻辑去比较也是可以的

日期类型格式化

Mysql 

SELECT DATE_FORMAT(NOW(),'%Y%m%d') -- 2020-08-31 17:46:17 转化为 20200831

 Hive

SELECT DATE_FORMAT(NOW(),'yyyyMMdd') -- 2020-08-31 17:46:17 转化为 20200831

日期字符串->时间戳

unix_timestamp:日期转时间戳函数

用法:unix_timestamp(string date)

返回值:   bigint

说明: 转换格式为“yyyy-MM-dd HH:mm:ss“的日期到UNIX时间戳。如果转化失败,则返回0。

参考链接: https://blog.csdn.net/weixin_37536446/article/details/82419601

 

select unix_timestamp('2018-09-05 12:01:03') 
from dw.ceshi_data;
结果如下:
1536120063

 

 

 时间戳->日期字符串

from_unixtime:时间戳转日期函数

用法:from_unixtime(bigint unixtime[, stringformat])

返回值: string

说明: 转化时间戳到当前时区的时间格式

select from_unixtime(1423306743,'yyyyMMdd') 
  from dw.ceshi_data;
结果如下:
20150207

 

获取当前日期的时间戳

select unix_timestamp() 
from dw.ceshi_data;
结果如下:
1536126324

 

posted @ 2020-08-29 15:01  可以看看你胖次吗  阅读(13291)  评论(0编辑  收藏  举报
Live2D