Date: How Long Ago?

Posted by ErichSteinboeck on 27 Aug 2008 20:23, last edited by James Kanjo on 10 Jun 2011 00:28

Tags: date date-format javascript

rating: +6+x

In several places (forum, private messages, last revision date, etc.) Wikidot pages use dates and timestamps that automatically calculate (either when hovering with the mouse or directly in the text) how long ago this was. Examples are

  • 15 Mar 2009 16:44 (move the mouse over the date to see the hovering text) or,

  • 15 Mar 2009 16:44

If you want dates that you type on your pages to also automatically show "how long ago'', here is how you can do it.

How it works

The syntax needed is

[[date timestamp <format="format<|agohover>">]]


  • < … > denote optional parameters
  • timestamp is the number of seconds between Jan 1, 1970 and the wanted date. To find this number for a specific date, see Code Wizard below.
  • format is an arbitrary text string that may include %modifiers, which are replaced by an actual (part of the) date or time. If not specified, format defaults to "%e''.
  • |agohover when specified displays a "hovering'' text ("nn seconds/minutes/hours/days ago") when the mouse is moved over any part of the displayed format string.

Code Wizard

To find out what code you should use on your page for a specific date:

Then copy/paste the displayed code into your page.


What you type … What you get …
[[date 1216153821]] 15 Jul 2008 20:30
[[date 1216153821 format="%d. %m. %Y|agohover"]] 15 Jul 2008 20:30
[[date 681746400 format="James is %O young"]] 09 Aug 1991 14:00
+++ Minutes from [[date 1234567890 format="%e %B|agohover"]]

Minutes from 13 Feb 2009 23:31


Note that currently:

  • the "how long ago" value for dates that lie in the future is clumsy (it's displayed as e.g. 28 May 2041 05:30) and
  • dates before Jan 1, 1970 are not rendered at all

Additional Note

Note that this How-To is also a good example for a (visually) seamless integration of a Wikidot page with Javascript code.

Check the source code to see how this can be done.



ErichSteinboeckErichSteinboeck. Please visit his/her userPage.

Related articles


Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.