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

  • Home
  • SEARCH
  • 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 an online booking system & need to exclude closed days from
I'm creating an online based system that has public user profiles for all users..
I'm creating an android app where user loads some data from an online server
I have an online order entry system in silverlight. I need to send an
I am creating an online order form for multiple products. I need to calculate
I'm creating an online poll from scratch which will be held in a database.
I am creating an online store website that needs the functionality to select a
I am looking into creating a global ID system for all of our online
I have the following sql query SELECT * FROM jos_jcalpro_events AS e LEFT JOIN
I am creating an online FAQ type system using php and mySQL. The following

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.