How to compare - One month

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r_amin
Forum Newbie
Posts: 3
Joined: Fri May 11, 2007 11:31 am

How to compare - One month

Post by r_amin »

I just want to know is the database date, One month old or not?

Code: Select all

 
    $todt = date("Y-m-d"); //Today
    $dbdt = date("Y-m-d", strtotime($row["date"]));//Database date
 

Code: Select all

 $expiry = $todt - one month;
How to minus 1 month

Code: Select all

 
if ($expiry > $today) { 
$new_status = "Expire"; 
} else { 
$new_status = "ok"; 
}
Please tell me how to calculate minus 1 month.
Or
any other way to compare 1 month (One month old or not).
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to compare - One month

Post by jackpf »

Code: Select all

$months = array(
'January'   => 31,
'February'  => ((date('L') == 1) ? 29 : 28),
'March'     => 31,
'April'     => 30,
'May'       => 31,
'June'      => 30,
'July'      => 31,
'August'    => 31,
'September' => 30,
'October'   => 31,
'November'  => 30,
'December'  => 31)
);
 
 
$one_month = 60 * 60 * 24 * $months[date('F')];
Like that?
Post Reply