【问题标题】:How to concatenate and format date and time to timestamp/datetime in Intersystems Caché database如何在 Intersystems Caché 数据库中将日期和时间连接并格式化为时间戳/日期时间
【发布时间】:2021-12-13 15:31:44
【问题描述】:

利用 Intersystems Cache 文档和我有限的 SQL 知识,我发现 Cache 有自己的内部方法将日期时间转换为六位整数,但我不知道如何将其恢复为人类可以理解的格式(我无法理解有关如何执行此操作的 Intersystems 文档)。我在 yyyy-mm-dd 中有一个日期列,在 hh:ss xm 中有一个文本时间列,我在 DBeaver 中工作。我需要 datetime 或 datetime2 中的一列。

SELECT appointment_date, CAST(appointment_start_time as TIME) ast,
       appointment_date + appointment_start_time as sdt
FROM foobar

例子:

appointment_date   ast          sdt

2016-09-21         14:30:00     64184

期望的结果:

appointment_date   ast          sdt

2016-09-21         14:30:00     2016-09-21 14:30:00

【问题讨论】:

    标签: intersystems-cache intersystems-iris


    【解决方案1】:

    您可以使用CASTCONVERT,而不是'+',使用STRING 进行连接

    STRING(CAST(appointment_date as VARCHAR) , ' ' , appointment_start_time)
    STRING(CONVERT(VARCHAR,appointment_date,105), ' ' , appointment_start_time)
    

    105 表示格式 dd-mm-yyyy

    【讨论】:

    • 谢谢。然后我能够转换为时间戳: {fn CONVERT(STRING(CAST(appointment_date as VARCHAR) , ' ' ,ointment_start_time), SQL_TIMESTAMP)}
    猜你喜欢
    • 2016-11-26
    • 2018-06-15
    • 1970-01-01
    • 2021-04-14
    • 2019-10-30
    • 2022-11-26
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    相关资源
    最近更新 更多