Parsing out "just" the time part of a datetime Column

I'm trying to parse out just the time of a date time function. I can convert the whole date to varchar successfully using

select createdDate
convert(varchar(155),CreatedDate,21)
from tbl_1

This gets me:
2010-12-27 03:00:26.593

what i want is just the time part: from the first character till the end
03:00:26.593


LVL 1
Auerelio VasquezETL DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
Hi. I believe you want code 108. SQL 2008 does have a separate TIME data type, but if character conversion works, you can try with 108 first.
0
Kevin CrossChief Technology OfficerCommented:
Here is an example. You may actually want 114, so showed that too.
DECLARE @createdDate DATETIME = '2010-12-27 03:00:26.593';
SELECT CONVERT(CHAR(8), @createdDate, 108) AS [hh:mi:ss]
     , CONVERT(CHAR(12), @createdDate, 114) AS [hh:mi:ss:mmm]
;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ephraim WangoyaCommented:


select CONVERT(varchar, CreatedDate, 114)
from tbl_1
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Kevin CrossChief Technology OfficerCommented:
Hmm. You did not like the way I said it above. :) jk. I am sure you just missed hitting refresh. I have done that about three times today because of being distracted.
0
Kevin CrossChief Technology OfficerCommented:
By the way, I did not show an example, but for SQL 2008 you can use the TIME data type as said previously.

DECLARE @createdDate DATETIME = '2010-12-27 03:00:26.593';
SELECT CONVERT(TIME(7), @createdDate) AS [TimeObj]
;

Open in new window

0
Ephraim WangoyaCommented:

@mwvisa1

My bad, did not see that
0
Kevin CrossChief Technology OfficerCommented:
No worries, I was sincerely trying to be funny. Have not said hello in awhile; good to see around the zone as usual.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.