Select Varchar as Date

前端 未结 4 1749
攒了一身酷
攒了一身酷 2020-12-20 07:02

I want to select a varchar field as a date field

For example a field has this value \"30.12.2011 21:15:03\"

and when i select this

select DAT         


        
4条回答
  •  鱼传尺愫
    2020-12-20 07:35

    Here is the answere to my question:

    CAST
    (
    SUBSTRING
    (field FROM 1 FOR 2)
    ||'.'||
    SUBSTRING
    (field FROM 4 FOR 2)
    ||'.'||
    SUBSTRING
    (field FFROM 7 FOR 4)
    AS DATE)
    

    This took me 5 hours to find this out, maybe there should be a "-" instead of "." but it works.

提交回复
热议问题