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

前端 未结 15 820
难免孤独
难免孤独 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 15:04

    I took mattbasta's approach because it's able to get the 'first day of next month' with a given date, but there is a tiny problem in calculating the $nextmonth. The fix is as below:

    $now = getdate();
    $nextmonth = ($now['mon'] + 1) % 13 + 1;
    $year = $now['year'];
    if($nextmonth == 1)
        $year++;
    else
        $nextmonth--;
    $thefirst = gmmktime(0, 0, 0, $nextmonth, $year);
    

提交回复
热议问题