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
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.
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.
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.
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"); } ?>
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 }
Try to use this:
date('t');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With