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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:41:30+00:00 2026-06-07T09:41:30+00:00

I’m using a custom PHP function to produce a visual calendar for a single

  • 0

I’m using a custom PHP function to produce a visual calendar for a single month that blocks out dates based on a table that contains an start date, and an duration – For example:

Calendar Example

…This is produced by data saying that the table should be blocked out for 4 days from the 14th, and 7 days from the 27th.

The query looks something like this:

  SELECT GROUP_CONCAT(DATE_FORMAT(start_date,'%d'),':', event_duration) AS info
    FROM events
   WHERE YEAR(start_date = '2012'
     AND MONTH(start_date) = '07'
ORDER BY start_date

(You could safely ignore the group concat and return the data as individual rows, that doesn’t really matter).

I’m looking for a modification to the query that would block out dates at the start of the month IF an event starts in the previous month, but its length takes it into the following.

For instance – in the above example, the event on the 27th is actually scheduled to last 7 days in the database, so if I ran the query for MONTH(start_date) = '08' I’d like to say the first two dates blocked out, which they wouldn’t currently be, because the start date that would block it out is not in the month being selected.

I’m fairly sure there’s a subquery or something in there to grab the rows, but I just can’t think of it. Any takers?

EDIT

The answer from Salman below pointed me in the directon I wanted to go, and I came up with this as a way of getting carryovers from the previous month to show as ‘1st’ of the month with the number of remaining days:

SELECT IF(MONTH(start_date) < '08', '2012-08-01', start_date) AS starter, 
       IF(MONTH(start_date) < '08', duration - DATEDIFF('2012-08-01',start_date), duration) AS duration
FROM EVENTS
WHERE YEAR(start_date) = '2012'
AND (MONTH(start_date) = '08' OR MONTH(start_date + INTERVAL duration DAY) = '08')

Obviously a lot of variables there to replace in PHP, so maybe there’s an even better way?

  • 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-07T09:41:32+00:00Added an answer on June 7, 2026 at 9:41 am

    Original Answer:

    Assuming that the month in question is 2012-07, you need this query:

      SELECT column1, column2, columnN
       FROM `events`
      WHERE `start_date` <= '2012-07-01' 
        AND `start_date` + INTERVAL `duration` DAY > '2012-07-01'
    ORDER BY start_date
    

    Revised Answer:

    Apparently you need a query that checks for overlapping (or conflicting) dates. The example dates are 2012-07-01 through 2012-08-01 and the query is:

      SELECT *
        FROM events
       WHERE '2012-08-01' > start_date
         AND start_date + INTERVAL duration DAY > '2012-07-01'
    ORDER BY start_date
    

    To constrain the start date and interval, you can use SELECT ... CASE statement:

    SELECT
    CASE 
        WHEN start_date < '2012-07-01' THEN '2012-07-01' 
        ELSE start_date
    END AS start_date_copy,
    CASE 
        WHEN start_date < '2012-07-01' THEN duration - DATEDIFF('2012-07-01', start_date)
        ELSE duration 
    END AS duration_copy,
    FROM ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.