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 791611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:51:57+00:00 2026-05-14T21:51:57+00:00

I have 2 databases. One is properties and the other is dates . In

  • 0

I have 2 databases. One is properties and the other is dates. In dates I have associated the land_id and a date (In YYYYMMDD format) which means that the date is not available.

I need to formulate a query that a user can specify a start and end date, and then choose a property for which dates are available (not in the date database). How do airline and hotel websites do this kind of logic? I was thinking about taking the date range and picking all days in between and doing a query where the dates do not match and ordering it by number of results, but I can see how that could easily turn into an intense query.

CREATE TABLE IF NOT EXISTS `dates` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `land_id` int(11) NOT NULL,
  `date` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=44 ;

--
-- Dumping data for table `dates`
--

INSERT INTO `dates` (`id`, `land_id`, `date`) VALUES
(43, 1, '20100526'),
(39, 1, '20100522'),
(40, 1, '20100523'),
(41, 1, '20100521'),
(42, 1, '20100525');
  • 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-14T21:51:58+00:00Added an answer on May 14, 2026 at 9:51 pm

    Having the Dates as VARCHAR will make it harder to write a query. I suggest
    to save the dates as DATE and use the following query.
    This should help:

    SELECT * FROM dates WHERE date NOT BETWEEN '<start_date>' AND '<end_date>'
    

    It selects the dates not being between the given range.

    I found a solution in the MySQL 5.1. reference in order to make it work with VARCHAR,too:

    SELECT STR_TO_DATE(date,'%Y%m%d') as real_date 
    FROM dates WHERE real_date NOT BETWEEN '<start_date>' AND '<end_date>'
    

    Or

    SELECT DATE(date) as real_date 
    FROM dates WHERE real_date NOT BETWEEN '<start_date>' AND '<end_date>'
    

    btw: <start_date> and <end_date> are placeholders. Insert the concrete dates there (in format YYYY-MM-DD).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two databases, one is an MS Access file, the other is a
I have some databases that have four files each; one for PRIMARY, IDX, IMAGE,
I have two SQL Server 2005 databases, one is for development and the other
I have a complex django object, which has properties of other class types. This
I have 2 SQLite databases, one downloaded from a server ( server.db ), and
I have seen a few different in-process SQL databases for .NET (including one from
I have a database table and one of the fields (not the primary key)
Let's say I have a Cat that has two properties: FavoriteKitten SecondFavoriteKitten These kittens
I have a script that appends some rows to a table. One of the
I have a database where one of the common queries is has a where

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.