Posted by ErichSteinboeck on 27 Aug 2008 20:23, last edited by GoVegan on 10 Jun 2011 00:28
Tags: date date-format javascript
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>">]]
where
- < … > 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.
Examples
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 |
Limitations
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.
Backlinks
Author
ErichSteinboeck. Please visit his/her userPage.
this is wonderful info, but…
I'd like to use dataforms so user will enter a date (year, month, day) and then this magical number (seconds from 1970) will be stored in my dataform.
So far i found only 2 ways to enter dates in wikidot: plain text field and comboboxes for year/month/day. But then i cannot sort by neither of these methods. I wish to start using [ [ date ] ] but no user will ever type seconds from 1970. I need simplier method.
here is form, don't be affraid of russian text, just look at comboboxes http://sky-tests.wikidot.com/planehistory:3
i need it somehow store real date. please help. thank you
The feature isn't available yet, but you can show your support for it being added.
Join the club :) Many people have wanted this feature for a while. You're right in that it is not yet available, and only some semi-working alternatives (e.g. text field or several combo-boxes) are available.
If you would like to show your support for this feature being added to Wikidot, I'd suggest that you vote up this page: Dataform date field.
A solution in the meantime (as Wikidot is such a small team of developers, it could be a while until the wish is implemented)
However, if you're looking for a solution in the meantime, I recently helped RobElliott with the same issue, giving a semi-automated way of ordering events by date on his Strathpeffer Village site, using the Wikidot API.
Dates can be entered in whatever format you prefer (e.g. "dd/mm/yyyy") into a text field, and my program then uses this value.
If you are interested, we can discuss it further over email (e.g. here).
Cheers,
Shane
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
…and it has worked perfectly for over a year now!
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.