MySQL Forums
Forum List  »  PHP

Re: Query with overall date range and start/end time ranges
Posted by: Rational Rabbit
Date: April 26, 2012 08:10PM

Thanks for the input, Rick.

yeah, I know. And I really should have had more information before throwing the question out there. I had assumed I would be pulling from a MySQL database when, as it turned out, the data is coming from an AS400, (the MySQL db comes in later) and I have no control over the originating database structure, so I'm stuck with the separate date and time fields and no way that I know to formulate an iSeries query to combine them.

I was also given erroneous information on the times - rather than ranges, there is simply a start time and end time. (StartTime on the Start Date, EndTime on the End Date)

That still left me with a problem. What I ended up doing is pulling the data according to the date range, then simply excluding anything not in the time range while iterating through the loop.

$DateString = " AND PDATE >= '$SDate' AND PDATE <= '$EDate'";
$OrderField = $Sdate != $EDate ? "PDATE" : "PTIME";
$Q = "SELECT * FROM {ASA400 Table} WHERE PUNIT = '$_POST[PUnit]'".$DateString." ORDER BY ".$OrderField;
$Result = i5_query($Q,$i5_conn);
Then, in the loop:
while($L = i5_fetch_array($Result))
   if(($L[PDATE] == $SDate && $L[PTIME] < $StartTime) || ($L[PDATE] == $EDate && $L[PTIME] > $EndTime))
      continue; // In PHP this goes to top of loop
    -- Remainder of loop code here -- 

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.