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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:11:54+00:00 2026-06-12T21:11:54+00:00

I am working on a PHP application that displays events. It generates a select

  • 0

I am working on a PHP application that displays events. It generates a select box that allows visitors to choose a month for which events should be displayed.

My problem is in regard to the select box, which should display not only months on which an event starts or ends, but also months during which an event is still taking place (even if it started months before and ends months later).

Here is what I’ve got at the moment, it’s pretty basic and only returns months on which events start.

SELECT 
  DISTINCT DATE_FORMAT(start,'%M %Y') as prettydate, 
  DATE_FORMAT(start,'%m%Y') as monthyear 
FROM 
  `events` 
WHERE 
  start >= NOW() 
ORDER BY 
  start ASC;

How can I also get February & July but also March, April, May & June 2014 in the result if the only event I’ve got in 2014 starts in February and finishes in July for example?

Thanks in advance for your help!

  • 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-06-12T21:11:56+00:00Added an answer on June 12, 2026 at 9:11 pm

    Assuming you don’t have any events that span more than 1 year, and using the following start/end dates:

    ('2012-01-01','2012-01-31'),
    ('2012-03-01','2012-03-31'),
    ('2012-05-01','2012-06-01'),
    ('2012-07-01','2012-07-31'),
    ('2012-09-01','2012-10-31'),
    ('2012-11-01','2012-11-30');
    

    this query:

    SELECT DISTINCT
      DISTINCT DATE_FORMAT(e.start + INTERVAL ids.id MONTH,'%M %Y') as prettydate, 
      DATE_FORMAT(e.start + INTERVAL ids.id MONTH,'%m%Y') as monthyear 
    FROM 
    (
      SELECT 0 AS id
      UNION SELECT 1
      UNION SELECT 2
      UNION SELECT 3
      UNION SELECT 4
      UNION SELECT 5
      UNION SELECT 6
      UNION SELECT 7
      UNION SELECT 8
      UNION SELECT 9
      UNION SELECT 10
      UNION SELECT 11
    ) ids,
      events e
    WHERE
      EXTRACT(YEAR_MONTH FROM e.start + INTERVAL ids.id MONTH) <=
      EXTRACT(YEAR_MONTH FROM e.end)
    ORDER BY 
      e.start + INTERVAL ids.id MONTH
    

    will return:

    prettydate      monthyear
    January 2012    012012
    March 2012      032012
    May 2012        052012
    June 2012       062012
    July 2012       072012
    September 2012  092012
    October 2012    102012
    November 2012   112012
    

    See http://sqlfiddle.com/#!2/12b08/3 for a working example.

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

Sidebar

Related Questions

Am working on an PHP application that involves multiple plans a user can select.
I am currently working on a php application that allows for users to schedule
I'm about to start working on a PHP application that allows a user to
I'm currently working on a PHP application that uses a MySQL database for its
I am currently working on a PHP application that puts me in the desperate
I am working on a php that application that uses ajax. On all the
I am working on web application that will use PHP & MySQL. Application will
We are working with a PHP application which has no concept of switch-able themes;
I'm working on making a website/web application that displays images every 5 or so
I am currently working on a PHP mysql application which has a grid with

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.