Domanda

All,

I've been wracking my brains trying to figure this one out. I need to convert SQL timestamp to a non-standard format that I haven't been able to find an easy way to convert to.

I need to convert:

1900-01-01 00:00:00.000

to

1/1/1900 12:00 AM

I've tried several combos of datepart with casting, but I haven't had much luck. I suppose I'll need to convert a couple of times to get what I want, but I figured I would ask the experts first.

Thanks!

È stato utile?

Soluzione 2

Well I ended up finding the desired result with a colleague.

Here is what it ended up being, just in case anyone else needs it.

SELECT CONVERT(VARCHAR(10), EDITDATE, 101) + ' ' + RIGHT(CONVERT(VARCHAR, EDITDATE,100),7) AS ConvertedDate

Altri suggerimenti

Are you just trying to format a date into a string? If so take a look at this page:

http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx

Towards the bottom of the page is something that looks just like what you are looking for:

SELECT CONVERT(VARCHAR(20), SYSDATETIME(), 22)  -->   06/08/11 1:30:45 PM
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top