Solved

append AM or PM

Posted on 2003-12-08
3
476 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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…
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…

752 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