tags:

views:

56

answers:

4

Hi,

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

A: 

Use date function:

if (date('t') == date('j'))
{
   ...
}
Branimir
+1  A: 

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
}
malonso
The `time()` calls are redundant since the current timestamp is what's used by default. Not that it matters though :)
BoltClock
D'oh. Good call w/that. Answer is updated.
malonso
+1  A: 

Try to use this:

date('t');
Alexander.Plutov
A: 

And here it is, wrapped up as a function:

function is_last_day_of_month($timestamp = NULL) {
    if(is_null($timestamp))
        $timestamp = time();
    return date('t', $timestamp) == date('j', $timestamp);
}
intedinmamma