Coverting datetime to HH:Mi in AM/PM format in SQL server 2000

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 437
--Sample Data
DECLARE @Sample TABLE
(
dt DATETIME
)

INSERT @Sample(dt) VALUES('20150331') -- YYYYMMDD ( 31st Mar, 2015)
INSERT @Sample(dt) VALUES('3:25 PM') -- Time value HH:MI PM

--Query
SELECT RIGHT(CONVERT(VARCHAR(20), dt, 100), 7) [HH:Mi AM/PM], dt [Date] FROM @Sample

Output:
[HH:Mi AM/PM]	Date 
12:00AM 2015-03-31 00:00:00.000
3:25PM 1900-01-01 15:25:00.000

Comments or Responses

Login to post response