代码之家  ›  专栏  ›  技术社区  ›  Andres Urrego Angel

在24小时后计算日期

  •  1
  • Andres Urrego Angel  · 技术社区  · 6 年前

    我的要求真的很傻,所以基本上我需要回到时间24小时在一个时间戳列在蜂巢。

    到目前为止,我尝试了两种不同的方法,但都没有成功:

     select 
     recordDate, --original date
     cast(date_sub(cast(recorddate as timestamp),1) as timestamp),  -- going one day behind without hour
    cast((cast(cast(recorddate as timestamp) AS bigint)-1*3600) as timestamp)  -- crazy year
     from mtmbuckets.servpro_agents_events limit 10;
    

    我的输出看起来:

    enter image description here

    我感谢你对我的支持。

    谢谢

    1 回复  |  直到 6 年前
        1
  •  1
  •   sandeep rawat    6 年前

    蜂巢没有正向功能。

    1创建自定义项。

    以秒为单位转换日期并计算(-24*60*60)秒,然后将int改回data。

    使用from_unixtime和unix_timestamp实现以下代码。

     select from_unixtime(unix_timestamp(recorddate) - 86400)
     from mtmbuckets.servpro_agen ts_events limit 10;;
    

    来自唯一时间 将具有给定模式的时间字符串转换为Unix时间戳(以秒为单位)。此函数的结果以秒为单位。

    Unix时间戳

    使用默认时区和默认区域设置,将格式为yyyy-MM-dd HH:MM:ss的时间字符串转换为Unix时间戳(以秒为单位),如果失败,则返回0:Unix时间戳('2009-03-20 11:30:01')=1237573801