Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 810
  • Last Modified:

Check Whether A Date Lies Between Two Dates Using SQL


Hi

I have a given date, lets call it MyDate. I wish to check whether this date lies between two dates in a table using SQL like This:

"Select * From TableName Where MyDate Between CrStart And CrEnd".

TableName represents a Table of Bookings For A Conference Room. CrStart and CREnd Represent existing Bookings for a Specific conference room. If Mydate lies between CrStart and CREnd then the request should be rejected as "Conference Room Not Available".

I hope I am making myself clear. SQL does not like the Select Statement as it is.

Can somebody help me with this please.

Thanks.
0
Nolanc
Asked:
Nolanc
4 Solutions
 
DhaestCommented:
Include the start and end date:

Select * From TableName Where MyDate >= CrStart And MyDate <= CrEnd

Exclude the start and end date

Select * From TableName Where MyDate > CrStart And MyDate < CrEnd
0
 
Ramkisan JagtapLead DeveloperCommented:
Your given statement is also correct statement, just check with your dates for the date format.
if the dates format for all the dates are not same then try to make it same and then use your statement.

"Select * From TableName Where MyDate Between CrStart And CrEnd"

regards,
Ram
0
 
bkokxCommented:
When using dates in a SQL Select note that for instance Feb 1, 2010 as text becomes #02/01/2010#
0
 
PrakashRaoBSCommented:
Try this..

Select * From TableName Where convert(varchar,MyDate,101) Between convert(varchar,CrStart,101) And convert(varchar,CrEnd,101)
0
 
NolancAuthor Commented:
Hi

Thanks for all your comntributions.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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