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
In order to get no. of days in month you can use either
date('t')
OR
cal_days_in_month(CAL_GREGORIAN, 8, 2003)
And if you wish to check if today is the last day of month us can use
if(date('d')==date('d',strtotime('last day of month'))){
//your code
}
strtotime offers many great features so check them out first
echo date('t'); /// it return last date of current month
Try to use this:
date('t');
Use php's function: cal_days_in_month
More details here
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
}
Using the modern DateTime object class:
$date = new DateTime('last day of this month');