Re: CONVERT to HH:MM AM/PM
From: Gregory A. Larsen (greg.larsen_at_doh.wa.gov)
Date: 04/27/04
- Next message: Alan Howard: "Re: Table Design Question"
- Previous message: dk: "Re: converting varchar to numeric"
- In reply to: Patrick Rouse: "CONVERT to HH:MM AM/PM"
- Next in thread: Take care of the formatting: "RE: CONVERT to HH:MM AM/PM"
- Messages sorted by: [ date ] [ thread ]
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. > >
- Next message: Alan Howard: "Re: Table Design Question"
- Previous message: dk: "Re: converting varchar to numeric"
- In reply to: Patrick Rouse: "CONVERT to HH:MM AM/PM"
- Next in thread: Take care of the formatting: "RE: CONVERT to HH:MM AM/PM"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|