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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:55:07+00:00 2026-05-25T20:55:07+00:00

How is it possible to use the BETWEEN function in MySQL, to search for

  • 0

How is it possible to use the BETWEEN function in MySQL, to search for dates in any year but between a specific day/month to a specific day/month? Or if it’s not possible using BETWEEN, how else could I accomplish it?

To be more descriptive, I am trying to add a seasonal search to my photo archive website. So if a user chose to search for “summer” photos, it would search photos taken between 21 June and 21 September, but from any year.

If Carlsberg made SQL, I think it would be 🙂

WHERE date BETWEEN 'xxxx-06-21' AND 'xxxx-09-21'

Many thanks

  • 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-25T20:55:07+00:00Added an answer on May 25, 2026 at 8:55 pm

    The solution given elsewhere, WHERE date.MONTH() || date.DAY() BETWEEN '0621' AND '0921', is a good one (and it’s well worth upvoting since it’s fine for most MySQL databases) but I’d like to point out that it (and most queries that involve per-row functions) won’t scale that well to large tables.

    Granted, my experience is that MySQL is not used that often for the sizes where it would make a huge difference but, in case it is, you should also consider the following.

    A trick we’ve used in the past is to combine extra columns with insert/update triggers so that the cost of calculation is only incurred when necessary (when the data changes), rather than on every select.

    Since the vast majority of databases are read far more often than written, this amortises that cost over all selects.

    For example, add a new column CHAR(4) called MMDD and whack an index on it. Then set up insert/update triggers on the table so that the date column is used to set this new one, based on the formula already provided, date.MONTH() || date.DAY().

    Then, when doing your query, skip the per-row functions and instead use:

    WHERE MMDD BETWEEN '0621' AND '0921'
    

    The fact that it’s indexed will keep the speed blindingly fast, at the small cost of a trigger during insert/update and an extra column.

    The cost of the trigger is irrelevant since it’s less than the cost of doing it for every select operation. The extra storage required for a column is a downside but, if you examine all the questions people ask about databases, the ratio of speed problems to storage problems is rather high 🙂

    And, though this technically “breaks” 3NF in that you duplicate data, it’s a time honoured tradition to do so for performance reasons, if you know what you’re doing (ie, the triggers mitigate the “damage”).

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

Sidebar

Related Questions

Possible Duplicate: What is the difference between a function expression vs declaration in Javascript?
Summary: is it possible to specify a port to use when querying WMI using
Possible Duplicate: C++: What's the difference between function(myVar) and (function)myVar ? I have seen
Possible Duplicate: What is the difference between save and saveAll function in cakephp? 66
I'm currently successfully using Win32 API's SendMessage function to send text between two threads
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
I have recently started looking into Google Charts API for possible use within the
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the
Is possible to use ArcSDE API in .NET(C#) ? http://edndoc.esri.com/arcsde/9.2/api/capi/dbconnects/dbconnects.htm Thanks
Is it possible to use a flash document embedded in HTML as a link?

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.