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 2000 Forums
 Transact-SQL (2000)
 Converting a SQL DateTime into different format

Author  Topic 

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-02-26 : 13:28:50
Given the date format:
YYYY-MM-DD HH:MM:SS.MS

Convert into:
YYYY-MM-DD-HH.MM.SS.000000

I've tried using PATINDEX to find the space and replace it with a '-' but that didn't work.

I've tried using DATEPART() to concatinate the date parts together with a '-', but that did date addition, and not string concatination.

Doing a CAST into varchar gave me "Febuaray 26 2002".

Any ideas on the direction I should go with this folks?
Thanks!

Michael
michaelp@televox.com

lfmn
Posting Yak Master

141 Posts

Posted - 2002-02-26 : 13:38:21
select replace(convert(varchar(30), getdate(), 121), ' ', '-')



SQL is useful if you don't know cursors :-)
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-02-26 : 13:49:07
That was exactly what I needed! Thanks!!
Forgot abotu good ol' replace.

Michael

Go to Top of Page
   

- Advertisement -