How to: Query Time only?

Hi,

I would just like to know if there's a simple way of querying a time disregarding the date. I mean, I want to query all employees that spends time on the office after 5pm. I don't care about the date, I just want the time... Im currently achieving this by using DATEPART function and concatenating it to resemble a time. Is there a shorter way of doing this?

cheers,

Paul June A. Domag

[422 byte] By [PaulDomag] at [2008-3-6]
# 1
Here is an example:

select convert(varchar,getdate(),108) [time]

oj at 2007-9-9 > top of Msdn Tech,SQL Server,Transact-SQL...
# 2

Hi,

Thanks. Works like a charm...

cheers,

Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,SQL Server,Transact-SQL...
# 3

FWIW, here's another variation on that topic:

SELECT RIGHT(STUFF(CONVERT(CHAR(22),GETDATE(),13),21,4,' '),9)

08:25:36

(1 row(s) affected)

And in case your HR department wants to track the overtime down to milliseconds, you can do:

SELECT CONVERT(CHAR(12),GETDATE(),114)

08:25:36:093

(1 row(s) affected)
--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. (http://www.sqlpass.de)

FrankKalis at 2007-9-9 > top of Msdn Tech,SQL Server,Transact-SQL...

SQL Server

Site Classified