Re: [PHP] datetime field - still a newbie

2002-07-25 Thread Alexander Ross

Thanks bunches


"John Holmes" <[EMAIL PROTECTED]> wrote in message
001101c233ba$3de3d430$b402a8c0@mango">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 MMDD 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




RE: [PHP] datetime field - still a newbie

2002-07-25 Thread John Holmes

> 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 MMDD 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




RE: [PHP] datetime field - still a newbie

2002-07-24 Thread David Freeman

 > 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

First up, extract your date as part of your query in a standard format -
if you're looking to do date manipulations you're probably going to be
benefit from extracting it as a unix timestamp.

Once you've got your date information, along with whatever else you're
extracting, you can then process it in php.

You'll most likely have some sort of while() loop to increment through
your query data.

While you're incrementing through you can do an test the date
information against "today" and "yesterday".  Have a read of the php
manual for date() and mktime() as you'll almost certainly need to use
these two functions.

Basically what you'll need to do is test to see if the date information
from your database query is the same as your date information based on
working out what "today" or "yesterday" are when expressed in the same
format as the date information from your database.

The rest is pretty much display stuff - substitute date information for
appropriate words as required.

Hope that heads you in the right direction.

CYA, Dave




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php