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

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

    You can use DateTime object like this to find out the first day of next month like this:

    $date = new DateTime('first day of next month');
    

    You can do this to know how many days left from now to the first day of next month:

    $date = new DateTime('now');
    $nowTimestamp = $date->getTimestamp();
    $date->modify('first day of next month');
    $firstDayOfNextMonthTimestamp = $date->getTimestamp();
    echo ($firstDayOfNextMonthTimestamp - $nowTimestamp) / 86400;
    

提交回复
热议问题