Solved

append AM or PM

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hyperlink data type in SQL 3 28
create an aggregate function 9 34
Sql server get data from a usp to use in a usp 5 16
SQL Query Help Top 1 and Distinct? 6 26
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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…

777 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