function NextDate($D, $M, $Y) { $dateVerification = MonthDays($M, $Y); if ($D > $dateVerification) { echo 'incorrect date , no such day'; return 'wrong date'; } // echo($dateVerification.'<br/>'); $response = array(); if ($dateVerification == $D && $M == 12) { $prevYear = $Y + 1; $prevMonth = 1; $prevDate = 1; $response = array('day' => $prevDate, 'month' => $prevMonth, 'year' => $prevYear); } elseif ($dateVerification == $D) { $nextYear = $Y; $nextMonth = $M + 1; $nextDate = 1; $response = array('day' => $nextDate, 'month' => $nextMonth, 'year' => $nextYear); } else { $D++; $response = array('day' => $D, 'month' => $M, 'year' => $Y); } return $response; }
function PrevDate($D, $M, $Y) { if ($D == 1 && $M == 1) { $prevYear = $Y - 1; $prevMonth = 12; $prevDate = MonthDays($prevMonth, $Y); $response = array('day' => $prevDate, 'month' => $prevMonth, 'year' => $prevYear); } elseif ($D == 1) { $prevYear = $Y; $prevMonth = $M - 1; $prevDate = MonthDays($prevMonth, $Y); $response = array('day' => $prevDate, 'month' => $prevMonth, 'year' => $prevYear); } else { $prevYear = $Y; $prevMonth = $M; $prevDate = $D - 1; $response = array('day' => $prevDate, 'month' => $prevMonth, 'year' => $prevYear); } return $response; }
return $numberOfDaysInYearMonth; } function MonthDays($M, $Y) { $response = array(); if ($Y >= 0 && $Y < 3000 && $M > 0 && $M <= 12) { //echo('true <br/>'); $var = IsLeapYear($Y); $numberOfFebruaryDays = 28; if ($var == 'true') { $numberOfFebruaryDays = 29; } $array = arrayInit($numberOfFebruaryDays); $iterator = 0; foreach ($array as $dayNr) { $iterator++; if ($iterator == $M) { $response = $dayNr; } } } return $response; } print_r(MonthDays(11, 2014)); echo '<br/>'; print_r(MonthDays(2, 2016)); echo '<br/>'; print_r(MonthDays(2, 2014)); echo '<br/>'; print_r(MonthDays(10, 2014)); echo '<br/>';