-4

My datetime that is stored in my DB, look like this:

2012-18-08 09:00:00

I want to get it in this format

dd.MM.yyyy - hh:mm

// expected output:
// 18.08.2012 - 09:00

How can I achieve that? Something like following

SELECT CONVERT(VARCHAR(10),Date,104) ??

I use MsSql 2008.

4

3 回答 3

4

Assuming SQL Server 2008 and previous versions:

SELECT CONVERT(VARCHAR(10),YourField,104) + '-' + 
       CONVERT(VARCHAR(5),YourField,108)

For SQL Server 2012:

SELECT FORMAT(YourField, 'dd.MM.yyyy - hh:mm')
于 2013-03-19T13:03:18.473 回答
2

Here you go: Date-Formats

SELECT CONVERT(VARCHAR(10),GETDATE(),104) + ' - ' + 
       CONVERT(VARCHAR(5),GETDATE(),108)

OUTPUT: 19.03.2013 - 18:35

Live Demo

于 2013-03-19T13:05:41.240 回答
0

In MySQL, there is a DATE_FORMAT() function (https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format).

In your case, I would use:

DATE_FORMAT(`col`, "%d.%m.%Y - %H:%i");
于 2013-03-19T13:04:00.653 回答