This topic is locked

Calculate Dates Excluding Weekends & Holidays

2/23/2011 9:01:50 AM
PHPRunner General questions
cyberjas2001 author

I tried to accomplish the following task, i have to calculate the ammount of days that a truck has been parked on my parking lot, the tricky part is that it has to exclude weekends and american holidays.
For Example: FreeTime is the value that I need to calculate with the rules explained before.
DateIn = The date the truck gets to my parking lot;

Freetime = (FLOOR(abs (now() - abs(DateIn))/(606024)/10)- WEEKENDS - HOLIDAYS);

limit=5;
if ($data["FreeTime"] == limit)

echo ('Your time expires today');

$row["rowstyle"]='style="background:32D85F"';
elseif ($data["FreeTime"] < limit)

echo ('You have 1 day left');

$row["rowstyle"]='style="background:FFE13B"';
elseif ($data["FreeTime"] > limit)

echo ('Your time has expired, your truck will be charged an extra $85');

$row["rowstyle"]='style="background:FF4D3B"';
Any Ideas? Thanks!!!

Sergey Kornilov admin 2/23/2011

Here are some ideas on how you can calculate the number of work days between two dates:

http://stackoverflow.com/questions/3352712/get-date-range-between-two-dates-excluding-weekends