Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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


0
Auerelio Vasquez
Asked:
Auerelio Vasquez
  • 5
  • 2
1 Solution
 
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
 
Ephraim WangoyaCommented:


select CONVERT(varchar, CreatedDate, 114)
from tbl_1
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now