More on Video Rental Script

wxdqz

New Member
Okay, I am at a milestone in my coding. Late fee calculation. I am not sure if there is something in PHP that can help me do this without alot of code, but if there is, please let me know.

Basically, I need a function that will check the current date, the date a video was rented out (with the number of days the renter has it for, 1 day, 2 days, 7 days, etc) and figure out how many days have passed since then. All it needs to return is the number of days late, if any.

THe problem I am having is coming up with the code that will get PHP to understand calander days. I was thinking of using an array to hold the number of days in each month (then an IF/ELSE structure to figure out leap years). That is all good, but getting the script to understand how to use this data isn't going very well.

The script has to understand year changes, month changes, and day changes. I do not need any clock times (8:00. 9:15, etc), just days, months, and years.

Any ideas? I am guessing it would need alot of WHILE structures, since all of my failed attempts used while structures. The only code that I can get to work right is on a single month basis...

if ( date('j') > ($rentedDay + 1)): // 1 = night rental.
$daysLate = $daysLate + (date('j') - ($rentedDay + 1));
endif;

So if the current date (date('j')) is greater than the day after the video was rented ($rentedDay + 1), then ($rentedDay + 1) would be taken away from (date('j')), giving me the # of days late. If the vid was rented on the 28th, and it is now the 30th, the forumla would look like this... 30 - (28 + 1) = 1 day late.

This is all well and good for a single month, but what if the vid was rented on the 28th and it is now the 1st of the next month? I cannot use the same formula at all, it breaks down.
 
Back
Top