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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:08:32+00:00 2026-05-25T14:08:32+00:00

I have some events in a MySQL database and I need to extract them

  • 0

I have some events in a MySQL database and I need to extract them to feed a calendar. Normal events are not a problem but I have some special events that could repeat on a yearly basis. My problem is how to extract these events. I tried this to get events in the interval [$ini_month, $ini_day] – [$end_month, $end_day]:

SELECT * FROM `events` 
WHERE `repeat`='1' AND 
    MONTH(`date`) BETWEEN '$ini_month' AND '$end_month' AND 
    DAY(`date`) BETWEEN '$ini_day' AND '$end_day'

For instance, if I have to get events from July 1st to July 7th, $ini_month=$end_month=7, $ini_day=1 and $end_day=7. In this case this query works, but if I have to get events from June 25th to July 7th it fails $end_day < $ini_day. So, please, could you help me to generalize this query to make it work against any input?

  • 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-25T14:08:33+00:00Added an answer on May 25, 2026 at 2:08 pm

    You have to treat the “boder months” specially.

    SELECT * FROM `events` 
    WHERE `repeat`='1' AND 
        MONTH(`date`) BETWEEN '$ini_month+1' AND '$end_month-1' OR 
        (MONTH(`date`) == $ini_month AND DAY(`date`) > '$ini_day') OR
        (MONTH(`date`) == $end_month AND DAY(`date`) < '$end_day')
    

    should work. But this is extremely ugly.

    Instead, you could do something like

    WHERE `repeat`='1' AND 
        MONTH(`date`) * 100 + DAY(`date`) BETWEEN $ini_month_day AND $end_month_day
    

    if you set $ini_month_day and $end_month_day to appropriate values.

    Be aware that this isn’t optimal as well, as you cannot use indexes this way.

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

Sidebar

Related Questions

I need some help creating a query for my mySQL database. I have recently
I need to have some object hanging around between two events I'm interested in:
I have a mysql database table that will store locations for buildings and events
The problem I have is when trying to insert some values ​​in the database
I have a mysql table named events. Some events are featured. I want to
Problem: Need to store field value when doing this query on my database. Have
I have some Categories (numbers) in a MYSQL database that I am trying to
I have some images in a mysql database stored as BLOB's. The maximum file
I have some onchange events setup in jQuery which are used to populate a
I have some elements with events bound. Before I remove those elements, do I

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.