SQL date format: dd / mm / yyyy hh: ss

I'm trying to find the date format: dd / mm / yyyy hh: mm.

I am using convert (varchar, rc.CreatedDateTime, ???). 131 is not what I want.

I seem to be able to find a terrible batch that is very close, but not this specific one, am I missing something clearly obvious or is there another function I can use?

+3


source to share


3 answers


You can use this, just replace getdate()

with your field:

select convert(char(10), getdate(), 103) + ' ' 
    + convert(char(8), getdate(), 108)

      

which gives you the results:

14/03/2012 17:05:47

      

If you just want an hour and a second then:

select convert(char(10), getdate(), 103) + ' ' 
    + Left(convert(char(8), getdate(), 108), 2) + ':'
    + Right(convert(char(8), getdate(), 108), 2)

      



Here is a helpful link with date / time conversions:

http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/

Based on your comment what it should be dd/mm/yyyy hh:mm

, then the request would look like this:

select convert(char(10), getdate(), 103) + ' ' 
    + Left(convert(char(8), getdate(), 108), 5) 

      

OR without LEFT()

select convert(varchar(10), getdate(), 103) + ' ' 
    + convert(char(5), getdate(), 108) 

      

+4


source


Assuming you need dd / mm / yyyy hh: mm not dd / mm / yyyy hh: ss



SELECT convert (varchar(10), rc.CreatedDateTime, 103) + ' ' + 
       convert(varchar(5), rc.CreatedDateTime, 108)

      

+3


source


SELECT CONVERT(CHAR(10), rc.CreatedDateTime, 103) + ' ' 
     + CONVERT(CHAR(5),  rc.CreatedDateTime, 108)
FROM dbo.[table_name];

      

+3


source







All Articles