You are here: Re: Difference between two dates « All PHP « IT news, forums, messages
Re: Difference between two dates

Posted by Chris B on 05/10/05 22:14

> $last_activity = '2005-04-28 18:38:49';
> $time_since_last_activity = time() - strtotime($last_activity);
> $days = (int) floor($time_since_last_activity / (24*60*60));
> $hrs = (int) floor($time_since_last_activity %
> ($days*24*60*60) / (60*60));
> $mins = (int) floor($time_since_last_activity %
> ($days*24*60*60 + $hrs*60*60) / 60);
> $secs = (int) floor($time_since_last_activity %
> ($days*24*60*60 + $hrs*60*60 + $mins*60));
> echo "Last activity: $days days $hrs hrs $mins mins $secs secs ago";


That works great but only if the $time_since_last_activity > 86400.
i.e. if the difference is less than a day, $days ends up as 0.something,
which floors to zero.

$hrs then = difference % (0*24*60*60 / 60*60) which is (0/3600).

I think it would be the same if the difference was < 1 hour and 1 min
and 1 sec respectively.

I tried running various if difference > 86400 {work out days] etc but
I've just got myself confused.

Is there a way to work the values if it is under < 1 day, < 1 hour etc.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация