Jump to content

evaluating dates in non well formed formats


nickelus

Recommended Posts

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'];
	}

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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.