Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL strip date from datetime

Tags:

sql

tsql

What is the best way to strip the date from a DATETIME so only time is left to do a comparison?

I know I can do the following:

CONVERT(DATETIME, CONVERT(VARCHAR(8), GETDATE(),8))

But this involves convert and characters. If I wanted to check whether a time (including minutes) was between two other times stored in DATETIME columns, is there an elegant way to do this without having to rely on converting to character strings?

like image 365
t3rse Avatar asked Jul 19 '10 16:07

t3rse


1 Answers

If you're using SQL 2008

SELECT CAST(GETDATE() AS TIME)
like image 120
Mike M. Avatar answered Oct 05 '22 17:10

Mike M.