Jump to content

return rows on date range


Canman2005

Recommended Posts

russell@2fl.co.uk ??

russell@twofl.co.uk ??

 

 

 

Hi all

 

I have a sql table which holds events for my website, in each row there is the following fields

 

id (auto increase)

title (text)

date_from (dates are stored as YYYY-MM-DD)

date_end (dates are stored as YYYY-MM-DD)

 

I then have a query which looks in that table and returns all rows that have todays date inside the "date_from" field, the query looks like

 

<?php
$meventssql = "SELECT * FROM events WHERE datefrom = '".date('Y-m-d')."'";
$meventsquery = @mysql_query($meventssql,$connection) or die(mysql_error());
while ($meventsrow = mysql_fetch_array($meventsquery))
{
?>
<?php print $meventsrow['title']; ?><br>
<?php
}
?>

 

How can I re-write the query, so that it uses the date_from & date_end and returns all rows which fall in between those dates, so a row with a date_from set to "2007-01-01" and the date_end set to "2007-01-03", it would then return that row on

 

2007-01-01

2007-01-02

2007-01-03

 

Does that make sense?

 

Been having a hunt around, but cant seem to find anything which would do this.

 

Can anyone help me?

 

Thanks in advance

 

Ed

Link to comment
Share on other sites

trying using between.  I can't remember the exact syntax since I am still learning mysql, but google the use of mysql between.  It would look something like this:

 

SELECT * FROM events WHERE BETWEEN datefrom = date(value) and date(value);

 

Hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.