Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date format returned as mm/dd/yyyy hh:mm:ss AM/PM

I am brand new to sql my company just kinda threw me head long into this and said do it. So any help is greatly appreciated. I am trying to get a date to come out in the format of mm/dd/yyyy hh:mm:ss AM/PM so for example a date of 09/26/2014 11:04:54 AM. I have tried using the code:

Select Convert(nvarchar,EntryDate,101)
From DB1

However that returns just 09/26/2014. I also tried

Select Convert(nvarchar,EntryDate,100)
From DB1

but this returns Sep 26 2014 11:04AM

Not sure where to go from here. Again thanks for the help. BTW I am using SQL Server 2012.

like image 322
Chad Portman Avatar asked Sep 26 '14 16:09

Chad Portman


1 Answers

You can use FORMAT function in sql

SELECT FORMAT(@date,'MM/dd/yyyy hh:mm:s tt')
like image 95
Raj K Avatar answered Oct 21 '22 18:10

Raj K