Solved

append AM or PM

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OSQL to execute sql command 26 26
Encrypting SQL Server 2014 or SQL Server 2016 4 31
What is this datetime? 1 20
SQLCMD Output to file from xpcmd_shell 6 21
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

820 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