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: 222
  • Last Modified:

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
0
mdiglio
Asked:
mdiglio
  • 2
  • 2
1 Solution
 
arbertCommented:
Narayana has a realy good article on this:

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


Brett
0
 
Melih SARICAIT ManagerCommented:
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
 
Melih SARICAIT ManagerCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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