将字符串转换为db2中的日期


生如夏花
2025-03-14 09:17:59 (6天前)


好的,我能够解决它。

我想将字符串“10-Feb-2019 11:20”转换为“DD-mm-yyyy hh24:mi:ss”。

我试过约会,但它没有用。我在其他线程上看到了翻译功能……

3 条回复
  1. 0# 林老爷的日常 | 2019-08-31 10-32



    在DB2中

    date

    没有时间成分。



    所以,试试吧

    to_timestamp()





    1. select to_timestamp(‘10-Feb-2019 11:20’, DD-Mon-yyyy hh24:mi’)

    2. </code>


    请注意,秒不在字符串值中,因此它们不应该在格式规范中。但是,最终值将有秒 - 全部设置为零。


  2. 1# 布偶的表弟派大星丶 | 2019-08-31 10-32



    如果你想要String - &gt;时间戳转换,试试这个:


    <a href =“https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0007107.html"rel =”nofollow noreferrer “>
    TO_TIMESTAMP

    (’10 -Feb-2019 11:20’,’dd-mon-yyyy hh24:mi’)



    to_timestamp

    是别名

    timestamp_format




    如果你只想要这个时间戳的另一个字符串表示(比如你的

    10-Feb-2019 11:20

    1. - GT;
    2. <code>
    3. 10-02-2019 11:20:00
    4. </code>
    5. ), 试试这个:
    6. <BR/>
    7. <a href =“https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0007110.html"rel =”nofollow noreferrer “>
    8. TO_CHAR
    9. </A>
    10. to_timestamp'10 -Feb-2019 11:20''dd-mon-yyyy hh24:mi'),'DD-MM-YYYY HH24:MI:SS'
    11. <BR/>
    12. <code>
    13. to_char
    14. </code>
    15. 是别名
    16. <code>
    17. varchar_format
    18. </code>


登录 后才能参与评论