Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert DateTime to Unseperated String 3

Status
Not open for further replies.

5lights

MIS
Nov 19, 2003
53
US
How do I convert a DateTime to an Unseperated string?
2006-03-30 07:00:05 to 200603300700(yyyymmddhhmm)

I got a DateTime to 20060330 by Convert(nchar(8),table.field,112)
but now I need to include the time.
 
Use the REPLACE command. Something like:
Code:
SELECT (Convert(NCHAR(8),table.field,112) + REPLACE((Convert(NCHAR(8),table.field,108), ':', '') AS NewDateTime

-SQLBill

Posting advice: FAQ481-4875
 
On top of my head:
Code:
declare @tte datetime
SET @tte = getdate()
print replace(replace(replace(convert(varchar(20),@tte,121),'-',''),':',''),' ','')

Borislav Borissov
 
BINGO.
Thats pretty good, you all came up with the same(relatively) answer....and it works. I'm now getting 200603300815 for 2006-03-30 08:15:32.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top