Apr 1, 2005 #1 9654 Programmer Aug 4, 2003 34 0 0 US i have a datetime field whose value is 2002-08-22 14:00:00.000 but i just want to return 02:00 PM how can it be done.
i have a datetime field whose value is 2002-08-22 14:00:00.000 but i just want to return 02:00 PM how can it be done.
Apr 1, 2005 #2 Moptop Programmer Sep 24, 2003 35 0 0 EU Hi You could use CONVERT ( varchar , @thedate , 8 ) This would give you hh:mm:ss Mark Upvote 0 Downvote
Apr 1, 2005 Thread starter #3 9654 Programmer Aug 4, 2003 34 0 0 US Thanks mark but this gives me just 14:00:00 how do i get the PM so that it shows 02:00 PM in this format Upvote 0 Downvote
Thanks mark but this gives me just 14:00:00 how do i get the PM so that it shows 02:00 PM in this format
Apr 1, 2005 #4 JamesLean Programmer Dec 13, 2002 3,059 0 0 GB Try this: Code: SELECT RIGHT('0' + LTRIM(SUBSTRING(CONVERT(varchar, @dt, 100), 13, 7)), 7) --James Upvote 0 Downvote
Apr 1, 2005 #5 Moptop Programmer Sep 24, 2003 35 0 0 EU You could do: print substring(cast(getdate() as varchar), 13, 7) But that does,'t give you "Seconds" -you could add DATEPART ( s, getdate()) to the string print substring(cast(getdate() as varchar), 13, 5) + ':' + str(DATEPART ( s, getdate()),2,0) + substring(cast(getdate() as varchar), 18, 2) --its worth checking if this works in all time zones - I am in the UK and it works Upvote 0 Downvote
You could do: print substring(cast(getdate() as varchar), 13, 7) But that does,'t give you "Seconds" -you could add DATEPART ( s, getdate()) to the string print substring(cast(getdate() as varchar), 13, 5) + ':' + str(DATEPART ( s, getdate()),2,0) + substring(cast(getdate() as varchar), 18, 2) --its worth checking if this works in all time zones - I am in the UK and it works