How to find first day of the next month and remaining days till this date with PHP

前端 未结 15 794
难免孤独
难免孤独 2020-12-08 14:36

How can I find first day of the next month and the remaining days till this day from the present day?

Thank you

15条回答
  •  隐瞒了意图╮
    2020-12-08 14:58

    Since I googled this and came to this answer, I figured I'd include a more modern answer that works for PHP 5.3.0+.

    //Your starting date as DateTime
    $currentDate = new DateTime(date('Y-m-d'));
    
    //Add 1 month
    $currentDate->add(new DateInterval('P1M'));
    
    //Get the first day of the next month as string
    $firstDayOfNextMonth = $currentDate->format('Y-m-1');
    

提交回复
热议问题