Function to extract only time from a date object?

Trunc() funciton is to get date part without time from a date object. Is there any function to get Time part of the date object?

more ▼

asked Dec 16 '09 at 02:20 PM in Default

dbkid gravatar image

131 8 10 11

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Use TO_CHAR(date,"<format>")


more ▼

answered Dec 16 '09 at 02:28 PM

Andrew Mobbs gravatar image

Andrew Mobbs
1.5k 1 3

Thanks a lot Andrew! Now I am able to extract time. But I have question, don't we have a function like Trunc() to get time part? Here do we need to use TO_CHAR() ? Thanks once again.
Dec 16 '09 at 02:30 PM dbkid
Thank you Andrew.
Dec 16 '09 at 02:58 PM dbkid
Sorry - the stuff I wrote about TRUNC() and strings was rubbish... its been a long day. I meant of course TRUNC() and numbers.
Dec 16 '09 at 03:10 PM Andrew Mobbs
(comments are locked)
10|1200 characters needed characters left

You can use extract() function also.

more on this web page

more ▼

answered Dec 16 '09 at 02:34 PM

Tariq Rahiman gravatar image

Tariq Rahiman
665 2 2 4

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Dec 16 '09 at 02:20 PM

Seen: 1052 times

Last Updated: Dec 18 '09 at 02:49 AM