Results 1 to 6 of 6

Thread: filter recordset by time of day (hour and minutes)

  1. #1
    Join Date
    Oct 2003
    Posts
    13

    filter recordset by time of day (hour and minutes)

    I am using MS SQL server and I want to filter my recordset by the time of day. I want the record to display only between 10:20pm and 10:50pm each day. how can I do this . Thank You for any help!

  2. #2
    Join Date
    Mar 2003
    Location
    NJ
    Posts
    201
    insert into a select 1,getdate()
    insert into a select 1,getdate()-1
    insert into a select 1,getdate()-2
    insert into a select 1,getdate()-3


    select * from a where convert(varchar(20),tim,8) between '18:00:00' and '21:00:00'

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    create table mytime (id int, time datetime)

    insert into mytime select 1,'02-22-2004 20:21:00'
    insert into mytime select 1,'02-23-2004 23:00:00'
    insert into mytime select 1,'02-22-2004 20:00:00'
    insert into mytime select 1,'02-24-2004 12:00:00'
    insert into mytime select 1,'02-24-2004 20:25:00'
    insert into mytime select 1,'02-25-2004 11:00:00'
    insert into mytime select 1,'02-27-2004 06:00:00'
    insert into mytime select 1,'02-27-2004 20:35:00'
    insert into mytime select 1,'02-27-2004 19:35:00'
    insert into mytime select 1,'02-27-2004 20:15:00'
    insert into mytime select 1,'02-24-2004 22:25:00'
    insert into mytime select 1,'02-25-2004 22:45:00'
    insert into mytime select 1,'02-26-2004 22:25:00'

    select * from mytime where convert(varchar(20),time,8) between '22:20:00' and '22:50:00'

  4. #4
    Join Date
    Mar 2003
    Location
    NJ
    Posts
    201
    I dont see anything different between your solution and my solution.
    Last edited by Claire; 03-17-2004 at 09:13 AM.

  5. #5
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    requirement is between 10:20pm and 10:50pm

  6. #6
    Join Date
    Oct 2003
    Posts
    13
    You guys are Great!! Thank You both!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •