Jump to content

Recommended Posts

Hi all

 

I have a database which contains events, the structure has two date fields, one is called "datefrom" and the other one is called "dateto", these two fields contain dates in the format YYYY-MM-DD.

 

"datefrom" represents the start date and then "dateto" represents the end date.

 

I have a query which returns all rows which have todays date within the start and end date, but it doesnt seem to be doing this correctly all the time, if at all.

 

Can anyone spot any issues I might have with it?

 

My query is

 

$eventssql = "SELECT * FROM events WHERE type = 2 AND datefrom BETWEEN CURDATE() AND CURDATE() + INTERVAL 6 DAY OR dateto BETWEEN CURDATE() AND CURDATE() + INTERVAL 6 DAY LIMIT 10";
$eventsquery = @mysql_query($eventssql,$connection) or die(mysql_error());

Make any sense?

 

Thanks in advance

 

Ed

Link to comment
https://forums.phpfreaks.com/topic/53474-date-range-query-issue/
Share on other sites

Thanks all, please ignore the type = 2 it isnt anything that is related to this problem, its just the type of event.

 

Maybe my QUERY is incorrect, basically I have a table which looks like

 

id  datefrom      dateto

1    2007-02-22  2007-03-05

2    2007-05-13  2007-06-23

3    2007-05-25  2007-07-23

 

the `datefrom` and `dateto` are dates in the format YYYY-MM-DD, the `datefrom` means the date the event starts and the `dateto` means the date the event ends.

 

What I want to run a query on this table, the query should know the current date in the format YYYY-MM-DD and return any rows which have todays date between the 'datefrom' and the 'dateto', so if todays date was 2007-05-31, it would return rows 1 and 2, this is because row 1  'dateto' ends on the 2007-03-05.

 

Further to this, is should show any rows which have a 'datefrom' date, starting 6 days before, so it would effectivly show events 6 days before they start.

 

Does that make much sense?

 

Can anyone help?

 

Many thanks in advance

 

Ed

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.