Date display as "yesterday" or "tomorrow"
Posted: Sat Oct 10, 2009 12:58 am
I want to display a mysql records entry date as either "today", "yesterday" or the actual date (i.e. 10/7/2009). See below attempt at condition for each option. For some reason, I keep getting the actual date as display return, eventhough I change the test record's entry date from today's date, yesterday's date and the day before yesterday. Ive been tweaking and adjust code all evening with no luck. Any thoughts on how I may accomplish this? Don't me tell there's a two liner piece of code out there that does this already?
Code: Select all
<?
ini_set('date.timezone', 'America/Los_Angeles');
?>
<?
$enteredby = $row['acctid'];
$newweightquery = "SELECT entrydt FROM table WHERE enteredby = $enteredby ORDER BY entrydt DESC LIMIT 1,1";
$newresult = mysql_query($newweightquery);
while($row = mysql_fetch_array($newresult)){
$dtdisplay = $row['entrydt'];
}
$todaysdt = date('Y-m-d',time());
$yesterdaysdt = date('Y-m-d',(strtotime('-1 day', strtotime($todaysdt))));
echo "today's date: $todaysdt <br>";
echo "yesterday's date: $yesterdaysdt <br>";
echo "Entry Dt of record in database: $dtdisplay <br>";
if($todaysdt == $dtdisplay){
echo "today";
}
elseif($yesterdaysdt == $dtdisplay){
echo "yesterday";
}
elseif($todaysdt <> $dtdisplay && $yesterdaysdt <> $dtdisplay){
echo date('m-d-Y',strtotime($dtdisplay));
}
?>