Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $date = new DateTime('2000-12-31');
- $date->modify('+1 month');
- echo $date->format('Y-m-d') . "n";
- $date->modify('+1 month');
- echo $date->format('Y-m-d') . "n";
- ?>
- The above example will output:
- 2001-01-31
- 2001-03-03
- <?php
- $d = new DateTime( '2010-01-31' );
- $d->modify( 'first day of next month' );
- echo $d->format( 'F' ), "n";
- ?>
- echo Date("Y-m-d", strtotime("2013-01-01 +1 Month -1 Day"));
- // 2013-01-31
- echo Date("Y-m-d", strtotime("2013-02-01 +1 Month -1 Day"));
- // 2013-02-28
- echo Date("Y-m-d", strtotime("2013-03-01 +1 Month -1 Day"));
- // 2013-03-31
- echo Date("Y-m-d", strtotime("2013-04-01 +1 Month -1 Day"));
- // 2013-04-30
- echo Date("Y-m-d", strtotime("2013-05-01 +1 Month -1 Day"));
- // 2013-05-31
- echo Date("Y-m-d", strtotime("2013-06-01 +1 Month -1 Day"));
- // 2013-06-30
- echo Date("Y-m-d", strtotime("2013-07-01 +1 Month -1 Day"));
- // 2013-07-31
- echo Date("Y-m-d", strtotime("2013-08-01 +1 Month -1 Day"));
- // 2013-08-31
- echo Date("Y-m-d", strtotime("2013-09-01 +1 Month -1 Day"));
- // 2013-09-30
- echo Date("Y-m-d", strtotime("2013-10-01 +1 Month -1 Day"));
- // 2013-10-31
- echo Date("Y-m-d", strtotime("2013-11-01 +1 Month -1 Day"));
- // 2013-11-30
- echo Date("Y-m-d", strtotime("2013-12-01 +1 Month -1 Day"));
- // 2013-12-31
- $time = new DateTime('2014-01-31');
- echo $time->format('d-m-Y H:i') . '<br/>';
- $time->add( add_months(1, $time));
- echo $time->format('d-m-Y H:i') . '<br/>';
- function add_months( $months, DateTime $object ) {
- $next = new DateTime($object->format('d-m-Y H:i:s'));
- $next->modify('last day of +'.$months.' month');
- if( $object->format('d') > $next->format('d') ) {
- return $object->diff($next);
- } else {
- return new DateInterval('P'.$months.'M');
- }
- }
- $start_dt = $starting_calculated;
- $next_month = date("m",strtotime("+1 month",strtotime($start_dt)));
- $next_month_year = date("Y",strtotime("+1 month",strtotime($start_dt)));
- $date_of_month = date("d",$starting_calculated);
- if($date_of_month>28){
- $check_date = false;
- while(!$check_date){
- $check_date = checkdate($next_month,$date_of_month,$next_month_year);
- $date_of_month--;
- }
- $date_of_month++;
- $next_d = $date_of_month;
- }else{
- $next_d = "d";
- }
- $end_dt = date("Y-m-$next_d 23:59:59",strtotime("+1 month"));
- $date = date('Y-m-d', strtotime("+1 month"));
- echo $date;
- foreach(range(0,5) as $count) {
- $new_date = clone $date;
- $new_date->modify("+$count month");
- $expected_month = $count + 1;
- $actual_month = $new_date->format("m");
- if($expected_month != $actual_month) {
- $new_date = clone $date;
- $new_date->modify("+". ($count - 1) . " month");
- $new_date->modify("+4 weeks");
- }
- echo "* " . nl2br($new_date->format("Y-m-d") . PHP_EOL);
- }
- $startDate = new DateTime( '2015-08-30' );
- $endDate = clone $startDate;
- $billing_count = '6';
- $billing_unit = 'm';
- $endDate->add( new DateInterval( 'P' . $billing_count . strtoupper( $billing_unit ) ) );
- if ( intval( $endDate->format( 'n' ) ) > ( intval( $startDate->format( 'n' ) ) + intval( $billing_count ) ) % 12 )
- {
- if ( intval( $startDate->format( 'n' ) ) + intval( $billing_count ) != 12 )
- {
- $endDate->modify( 'last day of -1 month' );
- }
- }
- $datetime = new DateTime("2014-01-31");
- $month = $datetime->format('n'); //without zeroes
- $day = $datetime->format('j'); //without zeroes
- if($day == 31){
- $datetime->modify('last day of next month');
- }else if($day == 29 || $day == 30){
- if($month == 1){
- $datetime->modify('last day of next month');
- }else{
- $datetime->modify('+1 month');
- }
- }else{
- $datetime->modify('+1 month');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement