Presto SQL - Converting a date string to date format

后端 未结 8 1625
谎友^
谎友^ 2020-12-14 14:58

I\'m on presto and have a date formatted as varchar that looks like -

7/14/2015 8:22:39 AM

I\'ve looked the presto docs and tried various

相关标签:
8条回答
  • 2020-12-14 15:47

    You can also do something like this

    date(cast('2016-03-22 15:19:34.0' as timestamp))

    0 讨论(0)
  • 2020-12-14 15:47

    SQL 2003 standard defines the format as follows:

    <unquoted timestamp string> ::= <unquoted date string> <space> <unquoted time string>
    <date value> ::= <years value> <minus sign> <months value> <minus sign> <days value>
    <time value> ::= <hours value> <colon> <minutes value> <colon> <seconds value>
    

    There are some definitions in between that just link back to these, but in short YYYY-MM-DD HH:MM:SS with optional .mmm milliseconds is required to work on all SQL databases.

    0 讨论(0)
提交回复
热议问题