Solved

append AM or PM

Posted on 2003-12-08
3
477 Views
Last Modified: 2008-03-06
I'm building a field that holds a TIME value by:
.
.
.
  DATENAME(hh, wDate) + ':' + DATENAME(mi, wDate) as myTime,
.
.

I'd like to add an 'am' or 'pm' to the string but don't see that as an option for either DATENAME or DATEPART
0
Comment
Question by:juststeve
[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
3 Comments
 
LVL 48

Assisted Solution

by:Mikal613
Mikal613 earned 100 total points
ID: 9896797
SELECT  
(SUBSTRING(CONVERT(VARCHAR(30), GETDATE(), 109), 13, 8) +
SUBSTRING(CONVERT(VARCHAR(30), GETDATE(), 109), 25, 2)) AS myTimeHHMISS
0
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 150 total points
ID: 9896859
DATENAME(hh, wDate) + ':' + DATENAME(mi, wDate) + case when datepart(hh, wDate) > 12 then ' PM' else ' AM' end as myTime,


Hilaire
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 9897066
It looks as if "wDate" is a datetime/smalldatetime data type; if so:

SELECT RIGHT(CONVERT(VARCHAR(24), wDate, 0), 7)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

624 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