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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:14:31+00:00 2026-06-05T05:14:31+00:00

I’m trying to select from the database to get the campaigns that dates fall

  • 0

I’m trying to select from the database to get the “campaigns” that dates fall into the month. So far i’ve been successful in grabbing rows that starts or ends inside the current month. What I need to do now is select rows that start in one month and ends a few months down the line ( EG: It’s the 3rd month in the year, and there’s a “campaign” that runs from the 1st month until the 5th. other example There is a “campaign” that runs from 2012 until 2013 )

I’m hoping there is some way to select via MySql all rows in which a capaign may run. If not should I grab all data in the database and only show the ones that run via the current month.

I have already made a function that displays all the days inbetween each date inside an array, which is called “dateRange”. I’ve also created another which shows how many days the campaign runs for called “runTime”.

Select all (Obviously)

$result = mysql_query("SELECT * FROM campaign");

Select Starting This Month

$result = mysql_query("SELECT * FROM campaign WHERE YEAR( START ) = YEAR( CURDATE( ) ) AND MONTH( START ) = MONTH( CURDATE( ) )");

Select Ending This Month

$result = mysql_query("SELECT * FROM campaign WHERE YEAR( END ) = YEAR( CURDATE( ) ) AND MONTH( END ) = MONTH( CURDATE( ) ) LIMIT 0 , 30");

Code sample

while($row = mysql_fetch_array($result))
{
$dateArray = dateRange($row['start'], $row['end']);

echo "<h3>" . $row['campname'] . "</h3> Start " . $row['start'] . "<br /> End " . $row['end'];
echo runTime($row['start'], $row['end']);
print_r($dateArray);
}

In regards to the dates, MySql database only holds start date and end date of the campaign.

  • 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-05T05:14:32+00:00Added an answer on June 5, 2026 at 5:14 am

    to detect overlap of date/times, you can do something like this:

    //range of dates to get overlap. means if any row in the database has
    //a day in its start/end range that falls between these days
    $startDate = '2012-06-01';
    $endDate = '2012-06-30';
    
    $sql = "SELECT *
        FROM campaign
        WHERE
            `start` < '$endDate'
            AND `end` > '$startDate'";
    

    that will find any row from campaign that has any day that falls between the $startDate and $endDate. This also works for all occurrences of campaign…:

    1. starts before $startDate and ends before $endDate (end date between date range)
    2. starts after $startDate and ends before $endDate (both start and end between date range)
    3. starts before $startDate and ends after $endDate (start and end encompass date range)
    4. starts after $startDate and ends after $endDate (start date between date range)

    Also, this query as it stands is has $startDate and $endDate as exclusive. Meaning that if something starts on 31-May (based on the example dates above) and ends on 1-Jun, it would not be included. If you want the dates to be inclusive, you can change the > and < to be >= and <= to include the start and end date.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.