How to find a date in SQL?

I have an event management system in which I want

If the event is registered for 5 days (January 21, 2009 to January 26, 2009) Then, if another person wants to register the event between January 22, 2009 and January 24, 2009, it will not allow registration. I want to check this with an SQL query, so please tell me how I can do this.

+3
source share
3 answers

SELECT *
FROM events e
WHERE (@startDate BETWEEN e.startDate and e.endDate)
OR (@endDate BETWEEN e.startDate and e.endDate)
OR (@startDate <e.startDate AND @endDate> e.endDate)

+4
source

To complete the other answers, you have a good article on How to Search for Date and Time Values โ€‹โ€‹Using SQL Server 2000

It reminds you of how date / time values โ€‹โ€‹are stored (two types of date and time data: date and time)

He also points out that Datetime and smalldatetime are similar to floating point, float and real data types in that they are approximate numbers. This means that the value obtained from SQL Server may be different from the value that was originally saved.

In addition, he warns database designers who do not always use date and time columns. During the creation of the database, each date / time column must be defined, whether it will store both dates and dates, only dates or times.

It closes with practical data / time requests .

You also have a good description of DATEADD and DATEDIFF here .

+5
source

Search for DATEDIFF in SQL Help.

+1
source

All Articles