RE: [PHP] Date +30 comparison

From: Date: Tue, 01 Sep 2009 17:49:38 +0000
Subject: RE: [PHP] Date +30 comparison
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-297565@lists.php.net to get a copy of this message
At 1:28 PM -0400 9/1/09, David Stoltz wrote:
Ok, this is how I finally managed to get it to work - I'm sure there are other ways, but this works: //Check to make sure the next eval date is more than 30 days away $d1 = date('Y-m-d', strtotime($todays_date . '+30 day')); $d2 = date('Y-m-d', strtotime($nextdate)); if($d1>$d2){ echo "Sorry, your next evaluation date must be at least 30 days away, Click BACK to continue."; exit;
You got it. Just transform any date to seconds and then compare those seconds to other seconds (taken from other dates) and evaluate. Dead simple. Also note that the strtotime() and date() combination provides some very nice features like keeping track of the resultant date. You don't have to worry about leap years, or months having 28-31 days, or anything like that -- it's all taken care of for you, pretty neat huh? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#297565) next »