PHP get next month first day and remaining days to this date

Below method is tweaked to take account of December. This method is leap-year safe. The day count must include floor().

$curMonth = date('n');
$curYear  = date('Y');
if ($curMonth == 12)
	$firstDayNextMonth = mktime(0, 0, 0, 0, 0, $curYear+1);
else
	$firstDayNextMonth = mktime(0, 0, 0, $curMonth+1, 1);

echo floor($daysTilNextMonth = ($firstDayNextMonth - time()) / (24 * 3600));

From above mktime calculation, not only get the number of days, we can count the hours and minutes till next month first day. Example:

$day_count = floor(($firstDayNextMonth - time()) / (24 * 3600));
$hour_count = floor(($firstDayNextMonth - time()) / (3600));
$minute_count = (($firstDayNextMonth - time()) / (60));

By Keenlio, February 20, 2014

2 Comments

  1. Thanks for the great list�I ll definitely try Wordbook to publish my blog posts directly to my facebook

  2. Joel says:

    Appreciate this post. Will try it out.

    Here is my page Irritable Bowel Syndrome Diet

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


two × = 14

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>