Checking dates

I’ve been looking for a while on here and google for some code that will compare dates from a mysql database against user inputted dates.

All I have been abled to find is when the start and end dates are in the same column not in 2 seperate columns, with the help of this forum, php.net and some trial and error i’ve come up with this. Use it if you want

$haystack = array(); 
$needle = array();

function createDateRangeArray($strDateFrom,$strDateTo) { 
  $aryRange=array(); 
  $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4)); 
  $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4)); 
  if ($iDateTo>=$iDateFrom) { 
    array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry 
    while ($iDateFrom<$iDateTo) { 
      $iDateFrom+=86400; // add 24 hours 
      array_push($aryRange,date('Y-m-d',$iDateFrom)); 
    } 
  } 
  return $aryRange; 
}
		while($row = mysql_fetch_array($result))
	{ 
		$strDateFrom = date('Y-m-d', mktime(0,0,0,1,1,2007)); 
		$strDateTo = date('Y-m-d', mktime(0,0,0,1,1,2008)); 
		$haystack = array_merge( $haystack, createDateRangeArray($strDateFrom,$strDateTo) ); 
	}

		$strDateFrom = date('Y-m-d', mktime(0,0,0,6,1,2007)); 
		$strDateTo = date('Y-m-d', mktime(0,0,0,7,1,2008)); 
		$needle = array_merge( $needle, createDateRangeArray($strDateFrom,$strDateTo) ); 

	
	foreach($needle as $pin) {
			if(in_array($pin, $haystack)) 
					{ 
							echo "Found<br>"; 
					} 
			else 
					{ 
							echo "Not Found<br>"; 
					}
	}

Moved from GENERAL PHP Help to Code Snippets

Sponsor our Newsletter | Privacy Policy | Terms of Service