Skip to content

Instantly share code, notes, and snippets.

@yvolkan
Created March 25, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yvolkan/581ca6a011f0ad18d73d to your computer and use it in GitHub Desktop.
Save yvolkan/581ca6a011f0ad18d73d to your computer and use it in GitHub Desktop.
How to create installment table
<?php
function nextMonths( $date ){
$dateArray = [0 => $date];
for( $i=1; $i<=12; $i++){
$new_date = date('Y-m-d', strtotime('+'.$i.' months', strtotime($date) ) );
$next_month = date('Y-m-d', strtotime('last day of next month', strtotime( end($dateArray) ) ));
if ( date('m', strtotime($new_date) ) != date('m', strtotime($next_month)) ){
$dateArray[] = $next_month;
} else {
$dateArray[] = $new_date;
}
}
return $dateArray;
}
$date = '2016-12-31';
print_r( nextMonths( $date ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment