Convert SQL DateTime format

How can I display a DATETIME value (2010-12-02 15:20:17.000) as 02/12-2010 15:20?

Answers


For SQL Server:

select stuff(convert(varchar, getdate(), 105), 3, 1, '/') + ' ' + left(convert(varchar, getdate(), 8), 5)

DateTime is a DateTime is a DateTime - it just holds a date and time and doesn't have any string representation, really.

See the CAST and CONVERT topic in the SQL Server Books Online for details - it shows all supported date formats that SQL Server supports.

For your source format (2010-12-02 15:20:17.000) you could probably use style no. 121

DECLARE @source VARCHAR(50)
SET @source = '2010-12-02 15:20:17.000'

DECLARE @Date DATETIME
SELECT @Date = CONVERT(DATETIME, @source, 121)

SELECT @Date

but your target format is a bit odd..... I don't see any "out of the box" style that would match your needs. You'll need to use some string manipulation code to get that exact format.


Need Your Help

Not a single method can be resolved

c++ eclipse

I couldn't find a propper title for my problem, so I'm going to explain this the best I can so you can understand it and help with my problems.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.