Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Format Date DD.MM.YYYY HH:MM:SS

How can I get a date like 'dd.mm.yyyy HH:MM:SS' I tried the following but it's not exactly what I'm looking for...

select convert(varchar(20),getdate(),113)

result: 14 Jul 2011 09:23:57

Thanks a lot Largo

like image 653
largo68 Avatar asked Jul 14 '11 07:07

largo68


People also ask

What is SQL Server date format?

SQL Date Data Types DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS. YEAR - format YYYY or YY.

How can get date and HH mm in SQL?

By using format code as 111 we can get datetime in “YYYY/MM/DD” format. By using format code as 112 we can get datetime in “YYYYMMDD” format. By using format code as 113 we can get datetime in “DD MMM YYYY HH:mm:ss: fff” format. By using format code as 114 we can get datetime in “HH:mm:ss: fff” format.


2 Answers

See http://msdn.microsoft.com/en-us/library/ms187928.aspx

You can concatenate it:

SELECT CONVERT(VARCHAR(10), GETDATE(), 104) + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108)
like image 95
Scoregraphic Avatar answered Oct 04 '22 13:10

Scoregraphic


A quick way to do it in sql server 2012 is as follows:

SELECT FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss')
like image 25
Imran Avatar answered Oct 04 '22 14:10

Imran