【问题标题】:Get difference between two dates in business hours (Redshift)获取营业时间内两个日期之间的差异(Redshift)
【发布时间】:2019-08-04 14:12:29
【问题描述】:

我有两个采用这种格式的日期,我想找出它们在工作时间的区别。

2019-03-07 00:34:08

假设周一到周五是 9 点到 5 点

编辑:忘了提到这必须是标准查询。我在 BI 工具中执行此操作,但它们还不支持 UDF。所以这在技术上不是亚马逊红移,但我找不到标签。

【问题讨论】:

    标签: amazon-redshift


    【解决方案1】:

    这实际上是一个相当复杂的问题,因为它涉及到:

    • 一天内的小时数
    • 在 9-5 以外跳过非工作时间
    • 跳过周末

    满足此要求的最佳方法是Create a Scalar Python UDF - Amazon Redshift,它接受两个日期的输入,然后输出差异。

    网上有很多计算时间的Python库和示例代码,例如:How to find the number of hours between two dates excluding weekends and certain holidays in Python? BusinessHours package

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 2020-03-22
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多