> I have a datetime field in one of my mysql tables...when displaying
some
> of
> my records I want to display the date in the aforementioned datetime
> field,
> but if the date is today I want to display "today" instead. If the
date
> is
> yesterday I want it to display that .... so I how do I compare the
date in
> my record to todays date? Thanks
I posted this response earlier...did you get it? Are you looking for a
MySQL solution or a PHP solution??
SELECT IF(TO_DAYS(CURDATE()) =
TO_DAYS(date_column),'Today',IF(TO_DAYS(CURDATE())-1 =
TO_DAYS(date_column),'Yesterday',date_column)) FROM your_table;
If you want a PHP solution, then just select the regular MySQL date
format YYYYMMDD and use something like this when looping through your
results.
switch($your_row['Date_Column'])
{
case date("Ymd"):
echo "Today";
break;
case date("Ymd",strtotime("-1 day")):
echo "Yesterday";
break;
default:
echo $your_row['Date_Column'];
}
Untested code, of course...
---John Holmes...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php