Determining the first available date off (next week)
Posted: Sun Oct 18, 2009 11:21 pm
I am currently working on a project and have almost everything else completed... for some reason I can not get my head or my code (I can get it to work a little...) to work for this part. I think I have been staring at my computer screens for too long. 
Description of problem and what I am trying to accomplish:
I need to find the first available date off for an employee who is requesting a day off. All requests for the next week must be made my the preceding Wednesday at 5:00 PM. I would like to pass today's date (timestamp) to a function and have it return the next available date for requests.
Example: (today's date -> before this Wednesday at 5 (bool) -> returns first available date)
4:00 PM Monday October 19, 2009 -> true -> Monday October 26, 2009
12:30 PM Wednesday October 21, 2009 -> true -> Monday October 26, 2009
5:30 PM Wednesday October 21, 2009 -> false-> Monday November 2, 2009
9:00 AM Thursday October 22, 2009 - > false -> Monday November 2, 2009
Some code I have... I think it works okay (only tested a few days) but it isn't in the format, as it only returns the difference between dates) I would like and it doesn't check the time.
Any help would be extremely appreciated.
Description of problem and what I am trying to accomplish:
I need to find the first available date off for an employee who is requesting a day off. All requests for the next week must be made my the preceding Wednesday at 5:00 PM. I would like to pass today's date (timestamp) to a function and have it return the next available date for requests.
Example: (today's date -> before this Wednesday at 5 (bool) -> returns first available date)
4:00 PM Monday October 19, 2009 -> true -> Monday October 26, 2009
12:30 PM Wednesday October 21, 2009 -> true -> Monday October 26, 2009
5:30 PM Wednesday October 21, 2009 -> false-> Monday November 2, 2009
9:00 AM Thursday October 22, 2009 - > false -> Monday November 2, 2009
Some code I have... I think it works okay (only tested a few days) but it isn't in the format, as it only returns the difference between dates) I would like and it doesn't check the time.
Code: Select all
// todays date
$today = date('Y-m-d');
// next monday
// first available day to request off
// if today is <7 days from monday get next +7
$nextMon = date('Y-m-d', strtotime('next Monday'));
$difference = daysDifference($today, $nextMon);
if($difference <=7){
$difference+=7;
}
function daysDifference($beginDate, $endDate){
//explode the date by "-" and storing to array
$date_parts1=explode("-", $beginDate);
$date_parts2=explode("-", $endDate);
//gregoriantojd() Converts a Gregorian date to Julian Day Count
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}