Re: CONVERT to HH:MM AM/PM

From: Gregory A. Larsen (greg.larsen_at_doh.wa.gov)
Date: 04/27/04


Date: Tue, 27 Apr 2004 13:33:33 -0700

Here is an example that use CAST, CONVERT and RIGHT plus the substring
funtion to accomplish what you are asking:

set nocount on
create table x (cdatetime varchar(20))
insert into x values(getdate())
insert into x values('04-01-2004 10:01')
select * from x
select right(convert(char(17),cast(cdatetime as datetime),109),5)+
right(convert(char(26),cast(cdatetime as datetime),109),2) from x
drop table x

-- 
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Patrick Rouse" <anonymous@discussions.microsoft.com> wrote in message
news:A1ED9109-40A6-4588-A871-88D54A7E698E@microsoft.com...
> I have a table storing the time as varchar(25), but want to display it on
a report as HH:MM w/ AM or PM, i.e. 12:05AM or 12:05PM (no date, just the
time)
>
> I've tried a bunch of CONVERT statements listed in the BOL and in previous
threads, but the best I've gotten is with 108 which gives me HH:MM:SS w/o
the AM/PM.
>
> Is there a way to do this with TSQL?
>
> Thanks.
>
>


Relevant Pages

  • Re: c equivilant to "copy"
    ... > Shagy wrote: ... >>I've been trying to find an equivant c funtion to ... >> How would I accomplish this? ...
    (comp.lang.c)
  • Re: Macros in Excel
    ... Strictly you can't delete a row with a worksheet function such as if, but, ... given more detail on what you are actually trying to accomplish, ... > How can I write a macro that will delte a row in an IF funtion if the ...
    (microsoft.public.excel.programming)