Jump to content

return rows on date range


Canman2005

Recommended Posts

[email protected] ??

[email protected] ??

 

 

 

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
https://forums.phpfreaks.com/topic/46738-return-rows-on-date-range/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.