Re: FN-FORUM: php date function
date posted 9th May 2006 16:47
> 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've grabbed this: (from http://us3.php.net/date)
>
> $date1 = mktime(0,0,0,1,1,2006);
> $date2 = mktime(0,0,0,date('m'),date('d'),date('Y'));
> $total_days = 0;
> while($date1 < $date2) { $total_days++; $date1 += 86400; }
> echo $total_days;
>
> but I guess is need to use something like this:
>
> $date1 = mktime(0,0,0,$lastinmonth,$lastinday,$lastinyear);
> $date2 = mktime(0,0,0,date('m'),date('d'),date('Y'));
> $total_days = 0;
> while($date1 < $date2) { $total_days++; $date1 += 86400; }
> echo $total_days;
>
> so how do I convert the 2006-01-01 record in my dB into the 3 required
> variables as above? ($lastinmonth,$lastinday,$lastinyear).
>
> or maybe there is another way of outputting it?
>
Hi,
Probably just as easy to do it in the database and extract the result;
something like:
select DATEDIFF( mydate, now() ) as days from ...
(DATEDIFF is non standard and I don't think it exists even in some MySql
versions, but most sqls will have something similar.
Graham
> I simply want to say, you where in $givendate, today is $todaysdate which is
> $dayspast since your last visit.
>
> Thoughts welcome!
> Thanks
>
>
> ---
> Mark Bell
>
> mob: 0774 086 1862
> office: 0870 383 4575
> fax: 0870 199 2149
> skype: m4rkbell, 020 8123 2862
> web: http://m4rk.biz
> email: [EMAIL REMOVED]
>
>
>
>