phpretard Posted December 14, 2010 Share Posted December 14, 2010 I am trying to compare values and if the month is not of 2 digits then the comparison goes wrong. Here is some hacked crap that doesn't work. if (strlen($_POST['m'] <= 1)){$month = "0".$_POST['m'];}else{$month = $_POST['m'];} if (strlen($_POST['d'] <= 1)){$day = "0".$_POST['d'];}else{$day = $_POST['d'];} <form> function GetDays(){ $Listd = '<select name="d">'; if (isset($_POST['d'])){$Listd .='<option value="'.$_POST['d'].'">'.$_POST['d'].'</option>';} for ($x = 1; $x <= date('d'); $x++) $Listd .= '<option value="'.$x.'">'.$x.'</option>'; $Listd .= '</select>'; return $Listd; } function GetMonths(){ $Listm = '<select name="m">'; if (isset($_POST['m'])){$Listm .='<option value="'.$_POST['m'].'">'.$_POST['m'].'</option>';} for ($x = 1; $x <= date('m'); $x++) $Listm .= '<option value="'.$x.'">'.$x.'</option>'; $Listm .= '</select>'; return $Listm; } Here is what I am comparing: Now: 201012141292327875 Submitted: 201110101292353200 // 2 digit month/day Now: 201012141292327984 Submitted: 2011991292353200 // not 2 digits month/day 2 hours is enough for me...can someone shed some light on this for me please? Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 14, 2010 Share Posted December 14, 2010 may it be because it handles it as a number and not as a string? =o oh and if that is the case, use this function to solve the problem: http://php.net/manual/en/function.number-format.php Quote Link to comment Share on other sites More sharing options...
phpretard Posted December 14, 2010 Author Share Posted December 14, 2010 Worked like a charm! Thank you. Quote Link to comment 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.