Solved

Format date in SQL query like (Month Day, Year)

Posted on 2009-05-05
12
793 Views
Last Modified: 2012-05-06
I am sure I must be just missing something, but what is the simplest way to output a datetime field to look like this:

May 5, 2009

when currently the field value is equal to this:

2009-05-05 13:05:03.530

It doesn't have to appear in the database in that format, just in the output of select statement.

Thanks!
0
Comment
Question by:hyphenpipe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 250 total points
ID: 24306821
select convert(varchar(10), getdate(), 101)
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24306828
from a table:

select convert(varchar(10), FIELDNAME, 101)
from tablename
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24306841
swap out 101 for 100...
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 60

Expert Comment

by:chapmandew
ID: 24306844
select convert(varchar(10), FIELDNAME, 100)
from tablename
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24306851
Also:
SELECT CONVERT(VARCHAR, GETDATE(), 107)

See reference:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24306913
this is all about datetime conversion game, you can see all available date time in SQL Server with very small script, have a look at my small article.

http://www.sqlhub.com/2009/04/list-of-all-available-datetime-format.html
0
 
LVL 6

Author Comment

by:hyphenpipe
ID: 24307646
I apologize for my error.  Although these are close (I am already doing something similar), I should have used a better example other than the month of May.

Is it possible to get the full month string as part of the date, i.e. December 7, 1941 rather than Dec 7 1941 without a case statement?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24307691
Not too easily...however,  Iwould suggest using a dates table, as I use in this article

http://blogs.techrepublic.com.com/datacenter/?p=326
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24307711
Try like this:
DECLARE @date DATETIME
SET @date = GETDATE()-28;
 
SELECT DATENAME(month, @date) + ' ' + SUBSTRING(CONVERT(VARCHAR, @date, 107), 5, 8)

Open in new window

0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 250 total points
ID: 24307717
Or use the original space from conversion in 107.
SELECT DATENAME(month, @date) + SUBSTRING(CONVERT(VARCHAR, @date, 107), 4, 8)

Open in new window

0
 
LVL 6

Author Closing Comment

by:hyphenpipe
ID: 31578110
I awarded 250 to chapmandew and 250 to mwvisa1.  I hope this is satisfactory.  Thanks for the help!
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24307998
hyphenpipe,

Glad to help.

Regards,
Kevin

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Backup skipping a few tables 7 58
How to place a condition in a filter criteria in t-sql? 12 85
Restrict result set 1 46
Replication failure 1 25
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question