469,610 Members | 1,920 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

time from datetime

Is here an easy way to get 9:00 PM from 5/1/2005 9:00:00 PM without
doing:
Cast(DATEPART(HOUR,xDate) as varchar(2)) + ':' +
Cast(DATEPART(MINUTE,xDate) as varchar(2))
lq

Jul 23 '05 #1
3 1674
Declare @Dt DateTime
Set @Dt = '5/1/2005 9:00:00 PM'
Print Convert(nvarchar(20), @Dt, 108)

Jul 23 '05 #2
On 9 May 2005 09:04:05 -0700, laurenq uantrell wrote:
Is here an easy way to get 9:00 PM from 5/1/2005 9:00:00 PM without
doing:
Cast(DATEPART(HOUR,xDate) as varchar(2)) + ':' +
Cast(DATEPART(MINUTE,xDate) as varchar(2))
lq


Hi lq,

Check out the various style options described under CONVERT in Books
Online. Depending on the formatting required, you could use one of the
examples below, or change them to your needs:

SELECT CONVERT(char(12), CURRENT_TIMESTAMP, 114)
SELECT SUBSTRING(CONVERT(char(23), CURRENT_TIMESTAMP, 121), 12, 12)
SELECT SUBSTRING(CONVERT(char(19), CURRENT_TIMESTAMP, 100), 13, 7)
SELECT SUBSTRING(CONVERT(char(25), CURRENT_TIMESTAMP, 131), 12, 14)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3
Of course!
I didn't consider the simple solution of trimming off the date portion
of a built-in time/date format. Too bad there's not an equivalent of
Convert...108 that yields hh:mm am/pm.
lq

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Gerrit Holl | last post: by
4 posts views Thread by Jan Danielsson | last post: by
3 posts views Thread by Jon Davis | last post: by
2 posts views Thread by DWalker | last post: by
4 posts views Thread by Maziar Aflatoun | last post: by
9 posts views Thread by Ron Adam | last post: by
25 posts views Thread by Brian | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.