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)
 Display Date as single number

Author  Topic 

lols
Posting Yak Master

174 Posts

Posted - 2009-05-12 : 05:40:14
How to display date as single value

05/12/2009 15:05:56 should be displayed as 05122009150556

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-12 : 05:44:46
select replace(replace(replace('05/12/2009 15:05:56','/',''),' ',''),':','')
Go to Top of Page

TheOne
Starting Member

6 Posts

Posted - 2009-05-12 : 05:45:48
select replace(replace(replace('05/12/2009 15:05:56','/',''),' ',''),':','')
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2009-05-12 : 05:48:05
Is there any other way of doing it rather than using so many Replace?
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-12 : 05:56:07
with out time
try this SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]

check these links for format of dates
http://www.sql-server-helper.com/tips/date-formats.aspx
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80563
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2009-05-12 : 06:09:25
and with time '108'...thanks
Go to Top of Page

TheOne
Starting Member

6 Posts

Posted - 2009-05-12 : 06:12:46
select replace(replace(convert(varchar,getdate(),101)+convert(varchar,getdate(),108),'/',''),':','')
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-12 : 06:17:47
quote:
Originally posted by lols

and with time '108'...thanks



welcome
Go to Top of Page
   

- Advertisement -