glenelkins Posted July 6, 2006 Share Posted July 6, 2006 HiThe following lines of code generate 2 dates. Now i want to compare if($weddingdate <= $groupdate) but this does not do anything. How would I compare the two?[code]$temp_wd = explode("-",$_POST['date']);$weddingdate = date("Y-m-d",mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]));$temp_gd = explode("-",$_POST['groupdate']);$groupdate = date("Y-m-d",mktime(0,0,0,$temp_gd[1],$temp_gd[0],$temp_gd[2]));[/code]cheersg Link to comment https://forums.phpfreaks.com/topic/13820-comparing-dates/ Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 the date function creates a string. you can't compare if one string is less than or equal to another string. For example, what do you expect php to do if you do this? if ('apples' <= 'oranges') { .. }you need to do like this:[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);if ($wed <= $group) { .. }[/code]the mktime() function creates the unix timestamp which is an integer value, which CAN be compared properly. Link to comment https://forums.phpfreaks.com/topic/13820-comparing-dates/#findComment-53732 Share on other sites More sharing options...
glenelkins Posted July 6, 2006 Author Share Posted July 6, 2006 ah yes, im a dumb ass lol.cheers Crayon Link to comment https://forums.phpfreaks.com/topic/13820-comparing-dates/#findComment-53733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.