February 5, 2007 at 8:22 am
HI. I'm trying to pull out just the time from a datetime field. I'm using this:CONVERT(varchar(20), dbo.MYDATE, 8) and it works, but gives me the time in this format:19:44:15 but I need it to be like this:7:44:15 PM.
I know its something easy, but I can't remember and I'm stuck. Does anyone have any ideas?
Thanks!!
Thanks!
February 5, 2007 at 8:40 am
Hello Anita,
You need to use the statement like this
Convert(Varchar(20), dbo.MyDate, 108)
Hope this helps you.
Thanks
Lucky
February 5, 2007 at 8:42 am
lucky,
here is how i have formatted some timedate information. you can modify an necessary.
LEFT(
CONVERT(VARCHAR,
GETDATE(),101) + --DD/MM/YYYY
LEFT(RIGHT(CONVERT(VARCHAR, --HH:MM:SS
GETDATE(),109),15),9) + SPACE(1) +
RIGHT(CONVERT(VARCHAR,
GETDATE(),109),2),
22) + SPACE(1) -- AM/PM
February 5, 2007 at 9:00 am
Thanks! I can work with this and get what I need.
Thanks!
February 6, 2007 at 9:32 am
or,
SELECT Stuff(Right(CONVERT(varchar(30), GetDate(), 9), 14), 9, 4, ' ')
February 6, 2007 at 9:35 am
Also useful is knowing where in Help to find information like this. Type F1 in Enterprise manager or query analyzer and search on "CAST and CONVERT".
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply