PHP - How to check if a date has passed

I am trying to check if a date has passed or if it is the future. If the end_date has passed then I do not want it to display. end_date is a MySQL timestamp. Right now all news articles are displaying even if their end_date has passed. Here is the code I am using to check if the date has passed:

function dateExp( $timestamp ){

   $exp = intval($timestamp);
   $today = intval( time() );


   if( $exp > today ) return true;
   else return false;

}

Here is the code that gets the articles and displays them:

$qry = "select *    
    	 from 	news
    	 where 	display='Y'
    	 order by priority, date_added, title";

$news = _execQry($qry);


foreach( $news as $n )
{
   if( dateExp($n['end_date']) ){
      echo '<h3>'. $n['title'] .'</h3>';
      echo '<p>'. $n['story'] ;
      echo '<br />Added on '. dateFormat($n['date_added']) .'</p><br />';
   }

}
This question and answers originated from www.stackoverflow.com
Question by (5/18/2009 12:41:21 AM)

Answer

I suggest that you trim the records inside the query that way you program has less data to process.

$qry = "select *
from news
where display='Y' and end_date >= CurDate()
order by priority, date_added, title";

Answer by

Find More Answers
Related Topics  php  mysql  time  timestamp
Related Questions