whitestream6 0 Junior Poster

I'm getting a bit better at PHP, but the datetime with databases is proving hard to do for this particular bit of coding, no matter how much I practise!
Here's my code (ignoring the database parts in the header):

//select the table
$result = mysql_query("select * from epdata1 order by airdate LIMIT 20;");

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
   $programme=$r["programme"];
   $channel=$r["channel"];
   #$airdate = strtotime($r['airdate']);
      $airdate = strtotime($r['airdate']);
      $now = strtotime("NOW");
$currentYear = date("Y", $airdate); // format of "Y" gives four digit year ie 2009 not 09
$yearOfDateFromDatabase = date("Y"); // the year of the record
if($yearOfDateFromDatabase == $currentYear)
$dateFormat = "F jS - g:ia"; // dateFormat = 24 December
else
$dateFormat = "F jS, Y - g:ia"; // dateFormat = 01 January 2010
// now use $dateFormat when displaying the date!
$airdateFormatted = date($dateFormat, $airdate);
   $sDate = date("F dS, Y - g:ia",$airdate);
   $episode=$r["episode"];
   $setreminder=$r["setreminder"];
echo "<tr><td><b>$programme</b></td><td>showing on $channel</td>";
echo "<td>$airdateFormatted</td><td>$episode</td><td>$setreminder</td></tr>";
}
?>

However, just one small problem to fix - how do I ensure that it only shows

$dateFormat = "g:ia"; // dateFormat = 24 December
else

(i.e. the airtime) on the day itself (without the date beforehand which is for events in the upcoming week, or in this case, TV programmes airing) using the if statement?

Thanks for all your help so far in my other threads on this situation. :icon_smile:

If I can figure out how to do this it will make my dynamic PHP sites better.