Re: FN-FORUM: php date function
date posted 9th May 2006 17:00
Quoting Mark Bell [EMAIL REMOVED]
>
> Afternoon brain teaser:
>
> I'm storing dates in a MySQL table (of last client visits) and want a count
> of how many days since the last visit.
>
> I'm storing the date in an 2006-01-01 format.
I think you might be doing this in the wrong place. MySQL is pretty
good at doing date calculations. You might be better off calculating
this in the database.
Assuming that you have the last visit date in a date column called
'last_visit' in a table called 'user', then you can do this:
select date_diff(curdate(), last_visit)
from user
where [whatever your where clause is]
Or. If you still want to do it in PHP there's no need for that loop,
you can do something like this:
$date1 = mktime(0,0,0,$lastinmonth,$lastinday,$lastinyear);
$date2 = mktime(0,0,0,date('m'),date('d'),date('Y'));
$total_days = ($date2 / $date1) / 86400;
You might want to stick an "intval" in there too.
Dave...