Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Decimal to Datetime

Author  Topic 

rockstar283
Yak Posting Veteran

96 Posts

Posted - 2011-06-17 : 17:44:21
Guys..I want to convert a decimal into datetime format..e.g.

20110101000000 should be converted to 2011-01-01 00:00:00

Is there any way to do that..

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-17 : 17:50:55
DECLARE @d decimal (18,0)

SET @d = 20110101000000

SELECT CAST(LEFT(CAST (@d as varchar(20)), 8) AS datetime)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -