0

How do I display/select SQL Server Datetime column 2015-01-23 to text style January 23, 2015? I'm using SQL Server 9. The basic syntax I'm using in my query is:

SELECT LastContactDate, LastProfileReceivedDate
FROM Location
WHERE (Account_Id = '499')

I've tried using CAST (datetime, lastcontactdate, 107) as Date and using the Convert function. most efforts have returned the same style.

My results will show as 2015-01-11 08:48:11.677 and 2015-01-10 16:17:48.000 but I need to show simply as January 11, 2015 and January 10, 2015. Thanks in advance for any help on this.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kiasport
  • 15
  • 3

1 Answers1

1

Try:

SELECT CONVERT(varchar(12), LastContactDate, 107)

Sample output:

Jan 11, 2015

Source: MSDN

If you NEED the full month name, you're going to be stuck with a much nastier query:

SELECT DATENAME(MONTH, LastContactDate) 
         + RIGHT(CONVERT(VARCHAR(12), LastContactDate, 107), 9)

Sample output:

January 11, 2015

Source: https://stackoverflow.com/a/19619119/74757

I suppose I better ask the question: why aren't you doing your date formatting in the UI?

Community
  • 1
  • 1
Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
  • That worked Cory! Thanks. I am using MS SQL SRV Mgt Studio 11 and I am writing the queries manually. Not sure how to effectively use the UI yet, but understand it's better to learn manually first....after using style 107 I decided to use style 101 instead. I have the MS SQL SVR 2008 Fundamentals book, but got confused on how to use the Convert function. Working great now. – Kiasport Jan 23 '15 at 21:40