RE: [PHP] Re: date
| From: | John Holmes | Date: | Thu, 25 Jul 2002 02:04:12 +0000 |
| Subject: | RE: [PHP] Re: date | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109401@lists.php.net to get a copy of this message | ||
> I am not sure it works, since isn't tested, but here we go. It's
pure
> Mysql, and it would be probaly easier, faster, and more readable to do
> with
> PHP mixed. But where's the fun of it? ;-)
>
> date_field is the name of your date column.
>
> $sql = "SELECT IF(DAYOFMONTH(date_field) = DAYOFMONTH(CURRENT_DATE),
> 'Today', IF (date_field = DATE_SUB(date_field, INTERVAL 1 DAYS),
> 'Yesterday', date_field)) FROM table"....
I don't think you want DAYOFMONTH. Otherwise if today is July 24th, then
a date column with June 24th, or any 24th, will come up as Today.
Something like this will work, though...
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;
Hope that helps...
---John Holmes...
> Julio Nobrega
> Pode acessar:
> http://www.inerciasensorial.com.br
>
>
> "Alexander Ross" <alexross@bleen.net> escreveu na mensagem
> news:20020724203928.45708.qmail@pb1.pair.com...
> > I have a column in one of my mysql tables which holds the date &
time
> that
> > the record was inserted. When I run a query later on I want to
display
> the
> > date, but if the date is today or yesterday I want to display
"today" or
> > "yesterday" instead .. how do i compare to stored date with todays
date?
> > todays date -1? Thanks
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php