Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a number to datetime sql

Tags:

sql

sql-server

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. Using CONVERT(DATETIME, Value) does not seem to work.

like image 938
Matt Seymour Avatar asked Feb 23 '23 12:02

Matt Seymour


1 Answers

SELECT  CONVERT(DATETIME, CAST(20110331 AS VARCHAR(8)), 112)
like image 132
Quassnoi Avatar answered Feb 26 '23 04:02

Quassnoi