Example to display next month’s date from current date without skipping any day or month in PHP

Want to display next month’s date from current date without skipping any day or month, here is the example:

<?php
$date = '31-01-2016';
echo nextDate($date);
function nextDate($currentDate){
 $getCurrentMonth = date("m",strtotime($currentDate));
 $getCurrentDate = date("d",strtotime($currentDate));
 $getCurrentYear = date("Y",strtotime($currentDate));
 $currentMonthplus = $getCurrentMonth+1;
 $getNextMonth = date("m",strtotime('+1 month',strtotime($currentDate)));
 
 if($currentMonthplus != $getNextMonth){
  $nextDates = date('t M Y', strtotime('01-'.$currentMonthplus.'-'.$getCurrentYear.''));
 }else{
  $nextDates = date("d M Y",strtotime('+1 month',strtotime($currentDate)));
 }
 return $nextDates;
}
?>

Example:

01-01-2016 | 01-02-2016
15-01-2016 | 15-02-2016
30-01-2016 | 29-02-2016
31-01-2016 | 29-02-2016
10-03-2016 | 10-04-2016
31-03-2016 | 30-04-2016

Advertisements

Dinesh Chhabra has written 1 article