Walker33 Posted May 5, 2009 Share Posted May 5, 2009 I'm trying to make an if statement dependant on the start date being greater than Jan 1, 2007. If my db field format was yyyy/mm/dd , then the way I'm going about it works fine. But format is mm/dd/yy, and I'm not getting the right result. Do I need to convert to yyyy/mm/dd (and if so, any help would be appreciated) or is there a way to do a > or < check against format mm/dd/yy format? Here's what I have: $selected_radio = $_POST['user_type']; // check table to see if they already exist as active user $query = mysql_query("SELECT * FROM customer_details WHERE FirstName = '$InitFName' AND LastName = '$InitLName' AND Email = '$InitEmail' and status = 'active'"); $num = mysql_num_rows($query); $result = mysql_fetch_assoc($query); if($num>0 && $selected_radio=='reporter' && $result["Start_Date"] > '01/01/07') Thanks. Quote Link to comment Share on other sites More sharing options...
Maq Posted May 5, 2009 Share Posted May 5, 2009 You probably want to compare dates with strtotime. You can convert it back to proper format with date. Quote Link to comment Share on other sites More sharing options...
suncore Posted May 5, 2009 Share Posted May 5, 2009 strtotime would be the easiest way to compare both dates ( doesn't matter if they are in mm/dd/yy or dd/mm/yy format ) - http://www.php.net/strtotime Quote Link to comment Share on other sites More sharing options...
Walker33 Posted May 5, 2009 Author Share Posted May 5, 2009 Thanks all, you steered me down the right path. Pretty new to this and didn't know strtotime . For anyone else in the future, I solved the issue by adding and changing: $my_date = $result["Start_Date"]; $my_time = strtotime($my_date); $datenew = date('Y-m-d',$my_time); if($num>0 && $selected_radio=='reporter' && $datenew > '2007-01-01') Great help, and greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Maq Posted May 5, 2009 Share Posted May 5, 2009 Thanks all, you steered me down the right path. Pretty new to this and didn't know strtotime . For anyone else in the future, I solved the issue by adding and changing: $my_date = $result["Start_Date"]; $my_time = strtotime($my_date); $datenew = date('Y-m-d',$my_time); if($num>0 && $selected_radio=='reporter' && $datenew > '2007-01-01') Great help, and greatly appreciated. Good, but in the future please be sure to use tags around code for proper formatting and syntax highlighting. 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.