Search through database for a specific timestamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elfranko
Forum Newbie
Posts: 4
Joined: Fri Jul 25, 2008 4:24 am

Search through database for a specific timestamp

Post by elfranko »

Hi all - first post yay!

Anyhow, am after a solution for this headscratcher if possible.

Scenario: I have holiday booking site two calendars to select a To and From date. These are fed into a function, along with a selected resortID and accommodationID.

In my accommodationDetails table, I have
ID resortID fromDate toDate accommodationnameID cost

The two ID's are for lookup tables and the dates are in unix timestamp format.
I have converted the fed in $FromDate and $ToDate into unix dates and worked out the number of nights between them by

Code: Select all

 
$secondsLeftOver = $ToDate - $FromDate;
$turnIntoDays = intval($secondsLeftOver / 86400);
$nightsStay = $turnIntoDays - 1; 
 
$nightsStay is now a number to use in a loop to make x nightsStay calls to the db to find out the cost of each night stay.

Now this could be done by using a sql call that has a WHERE $FromDate is => than fromDate and < toDate sort of idea but the catch is that each accommodation has multiple dates and costs which differ.

ie
Flat A Nov14-Dec20 = £79 Dec21-Dec26 = £87 etc etc

and the booking could go over these boundaries, ie how do I search if the fromDate is Dec20 and toDate is Dec24?

thanks in advance

frank
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Search through database for a specific timestamp

Post by Christopher »

I am not exactly sure of the question, but I think you will need to have separate checks for either the start or end date being in bounds.
(#10850)
Post Reply