RE: FN-FORUM: php date function
date posted 9th May 2006 17:07
From famine to feast, I'm now spoilt for choice!
Thanks eversamuch guys
-----Original Message-----
From: [EMAIL REMOVED] [EMAIL REMOVED] On Behalf Of
[EMAIL REMOVED]
Sent: 09 May 2006 17:59
To: FN-FORUM / [EMAIL REMOVED]
Subject: Re: FN-FORUM: php date function
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...
--
Freelancers, contractors earn more with Prosperity4
Call 0870 870 4414 or visit www.prosperity4.com
and benefit from Inland Revenue approved expenses today.
To advertise here: http://www.freelancers.net/advertising.html