Canman2005 Posted May 29, 2007 Share Posted May 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/ Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 What field types are said fields? Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/#findComment-264316 Share on other sites More sharing options...
AndyB Posted May 29, 2007 Share Posted May 29, 2007 but it doesnt seem to be doing this correctly all the time, if at all. Covers a multitude of sins. What's the type=2 about? Whether it makes sense depends on your expectations ... which are what when expressed logically? Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/#findComment-264317 Share on other sites More sharing options...
thegod Posted May 29, 2007 Share Posted May 29, 2007 Try changes the Cap locks words Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/#findComment-264324 Share on other sites More sharing options...
AndyB Posted May 29, 2007 Share Posted May 29, 2007 Try changes the Cap locks words Lord, I learn something new every day. Sometimes useful stuff, other times ... Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/#findComment-264328 Share on other sites More sharing options...
thegod Posted May 29, 2007 Share Posted May 29, 2007 try get the query from your database programme ussally make it for you Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/#findComment-264331 Share on other sites More sharing options...
Canman2005 Posted May 31, 2007 Author Share Posted May 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53474-date-range-query-issue/#findComment-265335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.