Converting a number to datetime sql

前端 未结 2 778
花落未央
花落未央 2021-01-06 15:10

I have the number 20080331.

I need to cast/convert this into a datetime so I can do a date comparison within the database. How will i go about converting this number

相关标签:
2条回答
  • 2021-01-06 15:38

    You need to cast to a character type first;

    select cast(cast(20080331 as varchar(8)) as datetime)
    
    >>2008-03-31 00:00:00.000
    
    0 讨论(0)
  • 2021-01-06 15:49
    SELECT  CONVERT(DATETIME, CAST(20110331 AS VARCHAR(8)), 112)
    
    0 讨论(0)
提交回复
热议问题