Solved

sql server - convert DATETIME to formated string

Posted on 2013-01-03
3
406 Views
Last Modified: 2013-01-03
Hi..
I have the following DATETIME field.   PURCHASED_DATE = 2013-01-02 09:00:00.000
I need to return the field / data in the following format

as

'Wed  Jan 2  9:00 AM'

thx
0
Comment
Question by:JElster
  • 2
3 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
Comment Utility
SELECT DATENAME(dw, GETDATE()) + ' ' + CONVERT(nvarchar(50), getdate(), 100)
0
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 150 total points
Comment Utility
sorry for just a link, but this should explain everything for you

http://www.sql-server-helper.com/tips/date-formats.aspx
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 250 total points
Comment Utility
If you really need a space between the time and AM/PM then you could do this:

SELECT DATENAME(dw, GETDATE()) + ' ' + replace(replace(CONVERT(nvarchar(50), getdate(), 100), 'AM', ' AM'), 'PM', ' PM')
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now