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 2005 Forums
 Transact-SQL (2005)
 Convert datetime to string

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2010-03-09 : 16:24:08
How to convert datetime to string?
For example, 2010-03-09 16:22:27.980 become 03092010162227

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2010-03-09 : 16:31:43
Declare @DT datetime
set @DT ='2010-03-09 16:22:27.980'


select replace(Convert(varchar(30),@DT,110),'-','') + replace(Convert(varchar(30),@DT,108),':','')


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2010-03-09 : 16:50:57
It works fine. Thank you!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-10 : 01:24:16
quote:
Originally posted by Sun Foster

How to convert datetime to string?
For example, 2010-03-09 16:22:27.980 become 03092010162227


If you want to show formatted dates in front end application, do formation there

Madhivanan

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

- Advertisement -