phpjquerymysqlhtmltimeago

timeago Jquery Plugin Date Format Problem


Here we go: I"m trying to implement the timeago jquery plugin (http://timeago.yarp.com/) on my project to show relative time (.i.e "2mins ago" instead of "1.10pm"). I have a field in my MySQL database which stores the timestamp of the current entry.

However, the timeago jquery plugin only works when the time is in UTC format "2008-07-17T09:24:17Z"

My first problem is: How to convert mysql timestamp to the above required format. My second problem: Even when I hardcode the required format in my code, the plugin does not work. Why?

My hardcode: In php file 1:

echo '<abbr class="timestamp" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>';

In index.php file 2

$("abbr.timestamp").timeago();

Of course, I've included the script tag properly. I can't figure out why it's not working. Note: I'm working on XAMPP, on my own computer (local).


Solution

    1. echo date(DATE_ISO8601, strtotime('2011-02-16 12:26:00'));
    2. Are you executing timeago when the DOM has finished loading? I.e.:

      jQuery(function ($) {
          $("abbr.timestamp").timeago();
      }