Solved

sql server - convert DATETIME to formated string

Posted on 2013-01-03
3
418 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
ID: 38739803
SELECT DATENAME(dw, GETDATE()) + ' ' + CONVERT(nvarchar(50), getdate(), 100)
0
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 150 total points
ID: 38739811
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
ID: 38739817
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

867 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

13 Experts available now in Live!

Get 1:1 Help Now