Tuesday, November 29, 2011

PHP: Payroll Dates


/***
* PayRoll Dates
* return array;
*/
  public function workDays($date='2011-12-17') 
  {
    if(!$date) {$date=strtotime("Last Saturday");
    } else { $date = strtotime($date); } 
  # find payroll dates ending last Saturday
    $workdays = array();
  # calculate 
    $workdays["sat"] = Date('Y-m-d', $date);
    $workdays["fri"] = Date('Y-m-d', strtotime('-1 day',$date));
    $workdays["thu"] = Date('Y-m-d', strtotime('-2 day',$date));
    $workdays["wed"] = Date('Y-m-d', strtotime('-3 day',$date));
    $workdays["tue"] = Date('Y-m-d', strtotime('-4 day',$date));
    $workdays["mon"] = Date('Y-m-d', strtotime('-5 day',$date));
    $workdays["sun"] = Date('Y-m-d', strtotime('-6 day',$date));

    $workdays["end"] = Date('Y-m-d', $date);
    $workdays["beg"] = Date('Y-m-d', strtotime('-6 day',$date));
    
#print_r($workdays);

    return $workdays;
  } 

No comments: