Its probably easier to do it in SQL:
SELECT s.seasonname, TO_DAYS(TIMEDIFF(GREATEST(booking.begin,
seasonbegin),LEAST(booking.end,season.end)))
FROM seasons s, booking
WHERE seasonbegin<=booking.end
AND seasonend>=booking.start;
Will give you a list of the seasons the booking overlaps with - it
should be evidence how to calculate the remaining days and to
consolidate this.
C.
--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP
SQL built-in date() function - is a very good tool to use when
working on date and time problem, but you might want to use this great
php date function.
http://learn-php-online.blogspot.com/2009/10/php-date-time-function.html
I hope it will help you :)
Nino Paolo Amarillento
http://best-sql-tutorials.blogspot.com/
--
Robert A. Gonzalez
http://twitter.com/RobertGonzalez
I have an idea. Doesn't mean you should do it.
How about you strtotime the start and end date of the block period.
Than, strtotime each date in the range. If it falls within the int
value of the start and end of the block period, then it's a high end
date. My next post will consist of entirely all caps simply because
they're the best way to get my point across without seeming like a
douche bag.
Am I the only one who bottom posts anymore?
--
-Jack Timmons
http://www.trotlc.com
Twitter: @codeacula
How about this one -> http://best-sql-tutorials.blogspot.com/2010/01/comparing-dates.html.
Hope that will help. It's a simple sql query.
Nino Paolo Amarillento
http://learn-php-online.blogspot.com/
http://learn-html-online-now.blogspot.com/
Nino Paolo Amarillento
Season start: 2010-02-16 (1266278400)
Season end: 2010-02-19 (1266537600)
Check-in: 2010-02-12 (1265932800)
Check-out: 2010-02-17 (1266364800)
Checkin to season: Low (4 days before High Season started)
Checkout from season: Low (2 days before High Season ended)
High Days: 0
Low Days: 5
Total Stay: 5 days
In that case just add 1 for low column and minus 1 for high column :)
http://best-sql-tutorials.blogspot.com/2010/01/comparing-dates.html.
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`get_high_low`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `get_high_low`(
STARTDATE DATE,
ENDDATE DATE,
SELECTSEASON VARCHAR(20)
)
BEGIN
DECLARE CURRENT_DAY DATE DEFAULT STARTDATE;
DECLARE SEASONSTART DATE;
DECLARE SEASONEND DATE;
DECLARE HIGH INT DEFAULT 0;
DECLARE LOW INT DEFAULT 0;
SELECT `start`, `end` INTO SEASONSTART, SEASONEND FROM dates WHERE
season = SELECTSEASON;
WHILE CURRENT_DAY <= ENDDATE DO
SET HIGH = HIGH + IF((CURRENT_DAY >= SEASONSTART) AND (CURRENT_DAY <
SEASONEND), 1, 0);
SET LOW = LOW + IF((CURRENT_DAY < SEASONSTART) OR (CURRENT_DAY >
SEASONEND), 1, 0);
SET CURRENT_DAY = DATE_ADD(CURRENT_DAY, INTERVAL 1 DAY);
END WHILE;
SELECT DATEDIFF(ENDDATE, STARTDATE) AS 'nights', HIGH AS 'high', LOW
AS 'low';
END$$
DELIMITER ;
--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP
I know you've choose already Davids code, it's a nice code too, but I
just modified my SQL version, I just wanted to share it. Please check
it out. I've entered lots of example dates. ==>
http://best-sql-tutorials.blogspot.com/2010/01/comparing-dates.html
I hope it will be helpful. :D
Cheers,
--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP
Total nights: 3 High nights: 1 Low nights: 2 Total nights: 5 High nights: 3 Low nights: 2 Total nights: 4 High nights: 4 Low nights: 0 Total nights: 9 High nights: 0 Low nights: 9
I didn't notice that :) anyway I have fixed it already. :D
Please check it out thanks => http://best-sql-tutorials.blogspot.com/2010/01/comparing-dates.html