Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the number of days of the current month? in PHP

Tags:

date

php

i want to check if today is the last day of the month, but i don't really know how. i want to write it in php.

can you help?

thanks, Sebastian

like image 783
sebastian Avatar asked Sep 11 '10 13:09

sebastian


People also ask

How do you calculate current days in month?

To get the number of days in the current month:function getDaysInCurrentMonth() { const date = new Date(); return new Date( date. getFullYear(), date. getMonth() + 1, 0 ). getDate(); } const result = getDaysInCurrentMonth(); console.

What is Cal_gregorian in PHP?

Description ¶ The names of the different calendars which can be used as calendar are as follows: 0 or CAL_GREGORIAN - Gregorian Calendar. 1 or CAL_JULIAN - Julian Calendar.

What does date () do in PHP?

The date/time functions allow you to get the date and time from the server where your PHP script runs. You can then use the date/time functions to format the date and time in several ways.

How can I get Saturday and Sunday of the month in PHP?

php function getSundays($y, $m) { return new DatePeriod( new DateTime("first sunday of $y-$m"), DateInterval::createFromDateString('next sunday'), new DateTime("last day of $y-$m 23:59:59") ); } foreach (getSundays(2014, 11) as $sunday) { echo $sunday->format("l, Y-m-d\n"); } ?>


2 Answers

There is probably a more elegant solution than this but you can just use php's date function:

$maxDays=date('t'); $currentDayOfMonth=date('j');  if($maxDays == $currentDayOfMonth){   //Last day of month }else{   //Not last day of the month } 
like image 119
malonso Avatar answered Sep 30 '22 21:09

malonso


Try to use this:

date('t'); 
like image 34
Alex Pliutau Avatar answered Sep 30 '22 22:09

Alex Pliutau