Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3600868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:32:59+00:00 2026-05-18T20:32:59+00:00

I am creating an online booking system & need to exclude closed days from

  • 0

I am creating an online booking system & need to exclude closed days from being booked & need a select query to see if the “date” (Christmas day) is >= [ClosedFrom] AND <= [ClosedTo]

Both ClosedFrom & ClosedTo are datetime columns in SQL Server 2008.

Here is what my table look like:

 ----------------------------------------------------------
 ClosedDateID     --     ClosedFrom     --     ClosedTo
 ----------------------------------------------------------
 1                --     2010-12-24     --     2010-01-04
 2                --     2011-04-20     --     2010-04-20
 ----------------------------------------------------------

The query below will hopefully show you what I am trying to achieve:

 SELECT [ClosedFrom],[ClosedTo]
 FROM [Package.Closed.Dates]
 where '2010-12-25' >=  [ClosedFrom] AND '2010-12-25' <= [ClosedTo] 

Thanks in advance for your help 😉


UPDATE:

Thanks Refilter for your answer but I still cannot get this to work 🙁 I have include some more details below.

Here is my table script:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Package.Closed.Dates](
    [ClosedDateID] [int] IDENTITY(1,1) NOT NULL,
    [ClosedDate] [datetime] NULL,
    [ClosedFrom] [datetime] NULL,
    [ClosedTo] [datetime] NULL,
 CONSTRAINT [PK_Package.Closed.Dates] PRIMARY KEY CLUSTERED 
(
    [ClosedDateID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Here is my table data:

INSERT INTO [dbo].[Package.Closed.Dates]
           ([ClosedDate]
           ,[ClosedFrom]
           ,[ClosedTo])
     VALUES
           ('2010-12-25'
           ,'2010-12-20'
           ,'2010-12-28'
GO

Here is my query to that checks a single date (ClosedDate) to see if we are closed (THIS RETURNS “we are CLOSED that day” – WORKING):

if exists (

SELECT [ClosedDate]
  FROM [Package.Closed.Dates]
  where [ClosedDate] =  '2010-12-25'

)

select 'we are CLOSED that day'

else 

select 'we are OPEN that day'

Here is your query to that checks between two dates (ClosedFrom & ClosedTo) to see if we are closed (THIS ALWAYS RETURNS “we are OPEN that day” – NOT WORKING):

if exists (

SELECT [ClosedFrom],[ClosedTo] 
  FROM [Package.Closed.Dates]
where '2010-12-25' between [ClosedFrom] AND [ClosedTo]  

)

select 'we are CLOSED that day'

else 

select 'we are OPEN that day'

I have also tried the below query (THIS ALWAYS RETURNS “we are OPEN that day” – NOT WORKING):


if exists (
SELECT [ClosedFrom],[ClosedTo] 
  FROM [MWD.Package.Closed.Dates]
where '2010-12-25' >= [ClosedFrom] AND '2010-12-25' <= [ClosedTo]
) select 'we are CLOSED that day' else select 'we are OPEN that day'

Just one other quick note, I need to see if the "date" (Christmas day) is >= [ClosedFrom] AND <= [ClosedTo]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:32:59+00:00Added an answer on May 18, 2026 at 8:32 pm

    This might work for you. This removes time component and makes it 00

    DECLARE @DateToCheck DATETIME
    SET @DateToCheck = '2010-12-25'    
    
    IF EXISTS ( SELECT 1   
                FROM [Package.Closed.Dates]   
                WHERE CONVERT(DATETIME,@DateToCheck,112) BETWEEN CONVERT(DATETIME, 
                      [ClosedFrom],112) AND CONVERT(DATETIME,[ClosedTo] ,112)
              )
       SELECT 'we are CLOSED that day'    
    ELSE     
       SELECT 'we are OPEN that day'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a GUI frontend for the Eve Online API in Python. I
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
I am creating an online application with five sections. Each section will have its
I am working on creating an online image editing tool.Looking for some refernce how
Lets say for example I am creating a an online shop. I have a
I'm creating a recommender system which most of calculations are going to be processed
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating an XPathDocument with referenced DTD sometimes throws a web exception. Why?
When creating a web application, and lets say you have a User object denoting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.