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)
 Convert back to datetime

Author  Topic 

learntsql

524 Posts

Posted - 2010-11-15 : 05:31:27
How to convert follwing output back to date/datetime value.
select CONVERT(varchar,GETDATE(),112)
TIA.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-15 : 05:43:57
select CONVERT(Datetime,CONVERT(varchar,GETDATE(),112))

But another method is

select dateadd(day,datediff(day,0,getdate()),0)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

learntsql

524 Posts

Posted - 2010-11-15 : 05:51:16
Sorry Madhi,
I didnt post properly..
I stored CONVERT(varchar,DateColumn,112) under bigint column,
In one of my query i have to convert this bigint back to datetime.
Is this possible?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-15 : 05:58:39
quote:
Originally posted by learntsql

Sorry Madhi,
I didnt post properly..
I stored CONVERT(varchar,DateColumn,112) under bigint column,
In one of my query i have to convert this bigint back to datetime.
Is this possible?



You should always use proper DATETIME datatype to store dates

select convert(datetime,cast(col as char(8))) from your_table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

learntsql

524 Posts

Posted - 2010-11-15 : 06:03:31
ThanX Madhi It worked great.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-15 : 06:12:39
quote:
Originally posted by learntsql

ThanX Madhi It worked great.



You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -