[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

How do I get the time only from a SQL datetime value?

I've googled this until my brain hurts and every example I try doesn't return the right thing.  I have this, in a datetime field:

'2007-03-17 13:25:00'

I need to query on the time only. (13:25:00)  How do I do this reliably?

Thanks!
0
Meshman333
Asked:
Meshman333
  • 4
  • 4
  • 3
  • +1
3 Solutions
 
waltersnowslinarnoldCommented:
SELECT CONVERT(CHAR(10),GETDATE(),8)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hello Meshman333,

select convert(varchar, datecolumn, 108 )

Regards,

aneeshattingal
0
 
sarabhaiCommented:
using Convert function,

SELECT CONVERT(CHAR(10),GETDATE(),8)

SELECT CONVERT(CHAR(10),GETDATE(),14)

0
Industry Leaders: 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!

 
Meshman333Author Commented:
Both of these return:

'2007-03-17 13:25:00'
0
 
waltersnowslinarnoldCommented:
Use your "date column name" where GetDate() is used.. you 'll reach the solution..
0
 
sarabhaiCommented:
Are u sure. In what version u run.
0
 
Meshman333Author Commented:
SELECT CONVERT(CHAR(10),GETDATE(),8)

SELECT CONVERT(CHAR(10),GETDATE(),14)

These return the date portion only.
0
 
waltersnowslinarnoldCommented:
SELECT CONVERT(CHAR(10),Your Date Column name,8)
0
 
Meshman333Author Commented:
This is Microsoft SQL Server 2008.
0
 
Meshman333Author Commented:
Sorry, they work, it's just me.  Thanks.
0
 
sarabhaiCommented:
SELECT CONVERT (time, GETDATE())
0
 
waltersnowslinarnoldCommented:
It has to work, Just give the column name, rather giving the '2007-03-17 13:25:00' value as such..
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now