RE: [PHP] datetime field - still a newbie

From: Date: Thu, 25 Jul 2002 09:04:11 +0000
Subject: RE: [PHP] datetime field - still a newbie
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109453@lists.php.net to get a copy of this message
> 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...

« previous php.general (#109453) next »