[thelist] Posted: [x] days ago - date last_modified?

Mark Groen mark at markgroen.com
Tue May 4 22:05:32 CDT 2004


----- Original Message ----- 
From: "Paul Bennett"
To: "rsusoeff" <thelist at lists.evolt.org>
Sent: May 4, 2004 6:32 PM
Subject: Re: [thelist] Posted: [x] days ago - date last_modified?


> >I see some news items and blogs with posting dates in this format:
> >
> >Posted: [x] days ago

> <self-promoting bluster>Having worked a lot with time critical web
> applications </self-promoting bluster>, finding php's strtotime()
> function was a boon - basically it gives you a value in seconds
from Jan
> 1, 1970 (from memory) to the time you pass it (you can pass it a
variety
> of date stamps). This gives you a benchmark to work from, as you
can
> take the current timestamp by using strtotime ('now), or simply
now()
> and then work out the difference in seconds between the post stamp
and
> the current stamp.
> Once you have the diff in seconds, translating to hours / days is
academic.
>
> >Examples:
> ><http://www.textism.com/>
> ><http://simon.incutio.com/>

The fellow responsible for textism also has a blog type CMS:
http://www.textpattern.com/  btw, it's a great little piece of blog
software if you want something with a small footprint. Everything is
in the db, and served up from same so there aren't indexes to rebuild
after you change your output template. Not for beginners install-wise
so ymmv, but I like it and am using it myself and for a couple
clients and they like it too.

The function he's written to do that looks like this, and you can see
it's actually been split to return three types of results. Those
familiar with JavaScript getTime() will recognize the 86400 value
(1000*60*60*24):

 function since($stamp)
 {
  $diff = (time() - $stamp);
  if ($diff <= 3600) {
   $mins = round($diff / 60);
   $since = ($mins<=1) ? ($mins==1) ? "1 minute":"a few
seconds":"$mins minutes";
  } else if (($diff <= 86400) && ($diff > 3600)) {
   $hours = round($diff / 3600);
   $since = ($hours <= 1) ? "1 hour" : "$hours hours";
  } else if ($diff >= 86400) {
   $days = round($diff / 86400);
   $since = ($days <= 1) ? "1 day" : "$days days";
  }
  return $since." ago";
 }

hth!

cheers,

               Mark

MG Web Services
Web Site Hosting and Development
www.markgroen.com
604-780-6917
Bowen Island, B.C., Canada



More information about the thelist mailing list