Help with a query

Hello,

With a date/time field that loks like this....4/25/2005 7:08:53 AM
Is there anyway to query just the time part?

background info:
I have a table that tracks user logins for computer labs in a school.
one field is logintime another is logouttime

I would like query the table to find a headcount of everyone who was logged in at half past the hour ( any hour )

This does NOT work
SELECT * FROM table
WHERE logintime < '10:29:59 AM' AND logouttime > '10:30:01 AM'

This does work, but for what I want to do it seems impractical
SELECT * FROM table
WHERE logintime < '4/25/2005 10:29:00 AM' AND logouttime > '4/25/2005 10:31 AM'

Thanks
LVL 16
mdiglioAsked:
Who is Participating?
 
Melih SARICAOwnerCommented:
try this

select convert(varchar(8),getdate(),108)

converting datetime value with 108 parameter ll give a result of time only

like 19:08:56


hope it helps

0
 
arbertCommented:
Narayana has a realy good article on this:

http://vyaskn.tripod.com/searching_date_time_values.htm


Brett
0
 
Melih SARICAOwnerCommented:
SELECT * FROM table
WHERE convert(varchar(8),logintime,108) < '10:29:59 AND convert(varchar(8),logouttime ,108)> '10:30:01'
0
 
mdiglioAuthor Commented:
Perfect!
Thank you very much
0
 
arbertCommented:
Just remember, it's one thing to display a time converted as varchar, but doing actual comparisons on a varchar converted time can be very inaccurate....
0
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.

All Courses

From novice to tech pro — start learning today.