chrisio Posted September 14, 2006 Share Posted September 14, 2006 Ok, I have a range of dates that my query searches through and returns the number of days that a given date range crosses, This works very well, however I now need to modify the query so that if it crosses through one range in particular it only returns that range.Set Date RangesHIGH SEASON DATES1 JANUARY - 4 JANUARY 20066 JULY - 6 SEPTEMBER 200621 DEC - 31 DEC 20061 JAN - 3 JAN 2007SHOULDER SEASON DATES9 FEBRUARY - 22 FEBRUARY 200630 MARCH - 26 APRIL 200625 MAY - 7 JUNE 200629 JUNE - 5 JULY 200619 OCTOBER - 1 NOVEMBER 2006LOW SEASON DATES5 JANUARY- 8 FEBRUARY 200623 FEBRUARY - 29 MARCH 200627 APRIL- 24 - MAY 20068 JUNE - 28 JUNE 20067 SEPTEMBER - 18 OCTOBER 20062 NOVEMBER - 20 DECEMBER 2006SPECIAL OFFER RATES24 FEBRUARY - 01 MARCH 2006$SD = 2006-02-24$ED = 2006-02-26if i were to feed the above set of dates to the below sql it would spit out both the row from the special offers (24 FEBRUARY - 01 MARCH 2006) and also the low season row (23 FEBRUARY - 29 MARCH 2006). What I need is where my variables are BETWEEN the special offers dates to only return those and where they are OUTSIDE those dates to return the other dates. I hope this is making sense.[code=php:0]$SD = $date_from (date(yyyy-mm-dd));$ED = $date;(date(yyyy-mm-dd));$VID = $_GET['vid']; (integer)$rid = $_GET['rid']; (integer) $seasons ="SELECT sdate , edate , band , datediff(edate,'".$SD."')+1 as days_overlap from season where '".$SD."' between sdate and edate and '".$ED."' > edate and rid = " . $rid . " and vid = " . $VID . "unionselect sdate , edate , band , datediff('".$ED."','".$SD."')+1 as days_overlap from season where '".$SD."' >= sdate and '".$ED."' <= edate and rid = " . $rid . " and vid = " . $VID . "unionselect sdate, edate, band, datediff(edate,sdate)+1 as days_overlapfrom season where sdate >= '".$SD."' and edate <= '".$ED."'and rid = " . $rid . "and vid = " . $VID . "unionSELECT sdate, edate, band, datediff( '".$ED."' , sdate )+1 AS days_overlapFROM seasonWHERE '".$ED."'BETWEEN sdateAND edateAND '".$SD."' <= sdateand rid = " . $rid ."and vid = " . $VID;[/code]Many Thanks in advanceChris Link to comment https://forums.phpfreaks.com/topic/20704-help-etending-this-query/ Share on other sites More sharing options...
fenway Posted September 14, 2006 Share Posted September 14, 2006 [quote author=chrisio link=topic=107998.msg434033#msg434033 date=1158224795]if i were to feed the above set of dates to the below sql it would spit out both the row from the special offers (24 FEBRUARY - 01 MARCH 2006) and also the low season row (23 FEBRUARY - 29 MARCH 2006). What I need is where my variables are BETWEEN the special offers dates to only return those and where they are OUTSIDE those dates to return the other dates. I hope this is making sense.[/quote]I don't know what you mean by this. Link to comment https://forums.phpfreaks.com/topic/20704-help-etending-this-query/#findComment-91770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.