【问题标题】:sql filter two dates from a string and calculate the differencesql从字符串中过滤两个日期并计算差异
【发布时间】:2021-05-27 03:47:04
【问题描述】:

我在 col1 select col1 from table; 中有一个字符串

blah blah from 2020-02-18T04:45:16.099-08:00[PST8PDT] to 2020-04-02T08:45:16.099-07:00[PST8PDT] blah blah

如何过滤from to 之后的日期并计算天数的差异?

【问题讨论】:

  • 您使用的是什么 SQL? T-SQL (SQL Server/Azure SQL)、PL/SQL (Oracle)、MySQL 还是其他?对于那个 SQL 变体,您是否查看过如何在 WHERE 子句中设置日期范围,或者如何计算两个日期之间的差异?

标签: sql presto trino


【解决方案1】:

没有正则表达式提取的示例:

trino> SELECT day(from_iso8601_timestamp('2020-04-02T08:45:16.099-07:00')
    ->          - from_iso8601_timestamp('2020-02-18T04:45:16.099-08:00'));
 _col0
-------
    44
(1 row)

(使用 Trino 352 测试)

【讨论】:

    猜你喜欢
    • 2021-07-02
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    相关资源
    最近更新 更多