Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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

Thank you

like image 902
Utku Dalmaz Avatar asked Nov 22 '09 00:11

Utku Dalmaz


People also ask

How to get next month from current date in php?

$date = date("Y-m-01"); $newdate = strtotime ( '+1 month' , strtotime ( $date ) ) ; This way, you will be able to get the month and year of the next month without having a month skipped.

How do you find the date of a day of the week from a date using PHP?

If your date is already a DateTime or DateTimeImmutable you can use the format method. $day_of_week = intval($date_time->format('w'));

How can I get tomorrow date in PHP?

$newDate = date('Y-m-d', strtotime('tomorrow')); echo $newDate; ?>


1 Answers

Create a timestamp for 00:00 on the first day of next month:

$firstDayNextMonth = strtotime('first day of next month'); 

The number of days til that date is the number of seconds between now and then divided by (24 * 60 * 60).

$daysTilNextMonth = ($firstDayNextMonth - time()) / (24 * 3600); 
like image 107
Benji XVI Avatar answered Sep 20 '22 02:09

Benji XVI