Converting a number to datetime sql

前端 未结 2 779
花落未央
花落未央 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
    

提交回复
热议问题