nickelus Posted July 29, 2009 Share Posted July 29, 2009 is it possible to take two dates in "m/d/Y" format and evaluate them in my code. I am triggering conditions that shouldn't be. The POST dates are in m-d-Y format generated by a php calendar but i would like the output to match the m/d/Y format of the rest of the dates in the database $curDate=date("n/j/Y"); if(isset($_POST['start_date'])){ if($_POST['start_date']>=$curDate){ $sDate=date("n/j/Y",$_POST['start_date']); }else{ $sDate=date("n/j/Y"); }} if(isset($_POST['end_date'])&&($_POST['end_date']<=$sDate)){ $eDate=$_POST['end_date']; echo "The End Date($eDate) must be after Start Date($sDate)Please go back & Fix!";exit; }else{ $eDate=$_POST['end_date']; } Link to comment https://forums.phpfreaks.com/topic/167976-evaluating-dates-in-non-well-formed-formats/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2009 Share Posted July 29, 2009 The only way you can compare dates (greater-than/less-than) is if the format has the year as the MSD (Most Sugnificant Digit) and the day as the LSD (Least Sugnificant Digit) and the formats and the length of each field are exactly the same. Formates like YYYY-MM-DD, YYYYMMDD, or YYYY/MM/DD (or using any other separator character) can be compared greater-than/less-than (edit: both values must be of exactly the same format.) Link to comment https://forums.phpfreaks.com/topic/167976-evaluating-dates-in-non-well-formed-formats/#findComment-885986 Share on other sites More sharing options...
nickelus Posted July 29, 2009 Author Share Posted July 29, 2009 if my date is coming out of the database as n/d/Y and i'd like to format it to match the date calendar format m-d-y before evaluating where am i failing Link to comment https://forums.phpfreaks.com/topic/167976-evaluating-dates-in-non-well-formed-formats/#findComment-885991 Share on other sites More sharing options...
nickelus Posted July 29, 2009 Author Share Posted July 29, 2009 the date (07-29-2009) is being interpreted some how as a date in the year 1970 and my results come out reverse high to low Link to comment https://forums.phpfreaks.com/topic/167976-evaluating-dates-in-non-well-formed-formats/#findComment-886065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.