Re: datetime field - still a newbie
| From: | Alexander Ross | Date: | Thu, 25 Jul 2002 17:22:06 +0000 |
| Subject: | Re: datetime field - still a newbie | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109551@lists.php.net to get a copy of this message | ||
Thanks bunches
"John Holmes" <holmes072000@charter.net> wrote in message
news:001101c233ba$3de3d430$b402a8c0@mango...
> > 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...
>
>
>