glenelkins Posted July 13, 2006 Share Posted July 13, 2006 HiSo i take 3 dates from a form. These are then run through a save script into the database. here is the code to take one of the dates from the form and convert to a unix stamp (the other 2 date boxes work the same):[code]$temp_wd = explode("-",$_POST['date']);$wed = mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]);$weddingdate = date("Y-m-d",$wed);[/code]now the next date comes as vars; $temp_gd, $group and $groupdate. How can I compare these two dates in an if statement? I want to test if $weddingdate > $groupdate. Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/ Share on other sites More sharing options...
zq29 Posted July 13, 2006 Share Posted July 13, 2006 You would pretty much just compare the timestamps...[code=php:0]<?phpif($timestamp1 > $timestamp2) echo "Timestamp 1 is more recent than timestamp 2";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/#findComment-57142 Share on other sites More sharing options...
Barand Posted July 13, 2006 Share Posted July 13, 2006 Provided $weddingdate and $groupdate have the same format (timestamp, Ymd or 'Y-m-d') then simplyif ($weddingdate > $groupdate) Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/#findComment-57143 Share on other sites More sharing options...
glenelkins Posted July 13, 2006 Author Share Posted July 13, 2006 I tried that many of times, it does not work Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/#findComment-57344 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 You tried what many times? Please post the code that you tried and failed.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/#findComment-57347 Share on other sites More sharing options...
glenelkins Posted July 15, 2006 Author Share Posted July 15, 2006 Here is the code, its does not work. Its supposed to return with header() but it carries on the code[code]$temp_wd = explode("-",$_POST['date']);$wed = mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]);$weddingdate = date("Y-m-d",$wed);$temp_gd = explode("-",$_POST['groupdate']);$group = mktime(0,0,0,$temp_gd[1],$temp_gd[0],$temp_gd[2]);$groupdate = date("Y-m-d",$group); //$groupremind = $_POST['groupremind']; if ($_POST['reminderdate'] != "") { $temp_grd = explode ("-",$_POST['reminderdate']); $remind = mktime(0,0,0,$temp_grd[1],$temp_grd[0],$temp_grd[2]); $groupreminddate = date("Y-m-d",$remind);} else { $groupreminddate = "00-00-0000";} if ($weddingdate < $groupdate) { header ("Location: index.php?page=2&message=Wedding Date Is Smaller Than The Group Tell Date");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/#findComment-58451 Share on other sites More sharing options...
Barand Posted July 15, 2006 Share Posted July 15, 2006 use exit() after a location headers.[code]if ($weddingdate < $groupdate) { header ("Location: index.php?page=2&message=Wedding Date Is Smaller Than The Group Tell Date"); exit();}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14450-compare-dates/#findComment-58457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.