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)
 Date conversion

Author  Topic 

sandesh.ravi
Posting Yak Master

110 Posts

Posted - 2011-11-15 : 10:50:58
A table stores the date value as
20111111111111.

Kindly let me know how to convert to date format dd/mm/yyyy.


Thanks,
Sandesh

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-15 : 10:58:55
you can do something like

SELECT STUFF(STUFF(STUFF(STUFF(STUFF(CAST(datefield AS varchar(30)),5,0,'-'),8,0,'-'),11,0,' '),14,0,':'),17,0,':') FROM table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-11-15 : 11:18:15
Any chance you can store your data in the proper data type instead?
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-15 : 11:41:13
Depends on what the format and datatype is but maybe a start is
select convert(datetime,left(fld,8),112)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sandesh.ravi
Posting Yak Master

110 Posts

Posted - 2011-11-15 : 12:16:14
Thank you..

Thanks,
Sandesh
Go to Top of Page
   

- Advertisement -