常州建站价格,云主机下载,wordpress禁止视频另存为,广告设计专业考研hive 常用日期处理函数
在工作中#xff0c;日期函数是提取数据计算数据必须要用到的环节。哪怕是提取某个时间段下的明细数据也得用到日期函数。今天和大家分享一下常用的日期函数。为什么说常用呢#xff1f;其实这些函数在数据运营同学手上是几乎每天都在使用的。
技术交…hive 常用日期处理函数
在工作中日期函数是提取数据计算数据必须要用到的环节。哪怕是提取某个时间段下的明细数据也得用到日期函数。今天和大家分享一下常用的日期函数。为什么说常用呢其实这些函数在数据运营同学手上是几乎每天都在使用的。
技术交流
技术要学会分享、交流不建议闭门造车。一个人可以走的很快、一堆人可以走的更远。
相关文件及代码都已上传均可加交流群获取群友已超过2000人添加时最好的备注方式为来源兴趣方向方便找到志同道合的朋友。 方式①、添加微信号dkl88194备注来自CSDN 加群 方式②、微信搜索公众号Python学习与数据挖掘后台回复加群 序号hive日期函数函数用法含参方式备注1to_date转化成日期to_date(string time)to_date(2023-5-20 05:20:00) 输出2023-5-202from_unixtime转化unix时间戳到当前时区的时间格式from_unixtime(bigint unixtime,[string format])select from_unixtime(1684559640,yyyyMMdd); 输出202305203unix_timestamp日期转化为unix时间戳unix_timestamp(string format)select unix_timestamp(); 输出1684559640 select unix_timestamp(2023-05-20 13:14:00); 输出16845596404date2datekeydate格式转化成datekeydate2datekey(string date/time)date2datekey(2023-05-20) 输出:202305205datekey2datedatekey格式转化为datedatekey2date(string datekey)datekey2date(20230520) 输出2023-05-206datediff返回开始日期减去结束日期的天数datediff(string enddate ,string begindate)select datediff(2023-05-20,2023-05-18); 输出27date_sub返回日期前n天的日期date_sub(string startdate,int days )date_sub(2023-05-20,2 ) 输出2023-05-188date_add返回日期后n天的日期date_add(string startdate,int days )date_add(2023-05-20,2 ) 输出2023-05-229year返回日期中的年year(string date)year(2023-05-20 11:32:12); 输出202310month返回日期中的月份month(string date)month(2023-05-20 11:32:12); 输出0511day返回日期中的天day(string date)day(2023-05-20 11:32:12); 输出2012hour返回日期中的小时hour(string date)hour(2023-05-20 11:32:12); 输出1113minute返回日期中的分钟minute(string date)minute(2023-05-20 11:32:12); 输出3214second返回日期中的秒second(string date)second(2023-05-20 11:32:12); 输出1215weekofyear返回日期在当前周数weekofyear(string date)weekofyear(2023-05-20 11:32:12); 输出2016unix_timestamp格式是timestamp精确到秒unix_timestamp(ymdhms2) - unix_timestamp(ymdhms1) -- 计算2个时间相差的秒数 (unix_timestamp(time1)-unix_timestamp(time2)) -- 同理若是计算相差的分钟就在以上基础再除以60小时天数也是同理 (unix_timestamp(time1)-unix_timestamp(time2))/60 -- 根据上述的函数计算后发现有小数点可用cast优化为以下 cast((unix_timestamp(time1)-unix_timestamp(time2))/60 as int) -- 相差的秒数。 CAST((unix_timestamp() - unix_timestamp(ymdhms)) % 60 AS int) -- 相差的分钟数。 CAST((unix_timestamp() - unix_timestamp(ymdhms)) / 60 AS int) % 60 -- 相差的小时数。 CAST((unix_timestamp() - unix_timestamp(ymdhms)) / (60 * 60) AS int) % 24 -- 相差的天数。 concat(CAST((unix_timestamp() - unix_timestamp(ymdhms)) / (60 * 60 * 24) AS int)