Solved

sql server - convert DATETIME to formated string

Posted on 2013-01-03
3
444 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
[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
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Lag Function DateDiff 2 26
SQL: get ride of blank rows 11 23
Do not display comma when no last name 8 48
Enable TLS 1.2 for SQL 2012 Web Edition 1 25
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

759 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