• 0

[sql] query to find entries between two time fields


Question

Hi All

I am writing an Appointment application,

Each appointment saved to the database is saved to the following fields,

StartTime and FinishTime (i.e. the time the appointment starts and the time the appointment finishes)

I am trying to write a SQL query to find any appointments within a given time.

For example,

i have saved an appointment in the database with a starttime of 09:00 and a finishtime of 10:00.

A user then wants to add an appointment for 09:30 to 10:30, so i would like to run a query, and in this example it would pull up from the database the appointment 09:00 to 10:00

I just can't seem to get the query right to perform the search.

I am using SQL Server 2008, i have tried the following query, but it doesn't return any results

use BookingManagerR1

select booking.title, booking.starttime, booking.finishtime

from Booking

where (starttime >= '09:30') and (finishtime <= '10:30')

I just can't seem to wrap my head around fixing this, any help would be really appreciated.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Found out the datetime field is not really a good field for performing querys on time, gonna convert the

application and database to use the time(7) field type in the database.

Edit : Sorry didn't see your post, thanks for the pointer, im gonna give it a try.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.