Hi,
I know, there is already a great plugin (relative date for kirby) for this usage, but I wanted something lighter, and without the “ago” and “years” etc append to the dates, and just the interval number in kirbytext.
So I wrote a quick tag, ultra-simple, so you can easily display date calculations without update it. It’s useful in a portfolio or resumé for displaying your age or your experience.
The syntax is easy, just write in the middle of your kirby text :
(from:2005) // calculate since 2005/01/01 to now
(from:1980-06-07) // calculate from this year, month and day to now)
(from:2005 to:2008) // calculate the interval between those years
(from:2005-10-31 to:2006-01-08 format:a) // calculate the number of days between those 2 dates (d and j are also accepted)
(from:2010-02 format:m) // calculate the number of months from february 2010 to now
// and finally, if you REALLY want something custom with tour own words :
(from:2007-02-15 format:it was %y year(s) and %m month(s) ago)
You can download it here, and copy it in site/tags (create the tags folder if necessary)
It’s based son strtotime, so a large set of syntaxes are accepted, you can try stuff like 01/02/2008, 01.03.1965 and so on (sometimes it changes the way days months and years are displayed, US or international style. See the code comments for further details.
This script is quick and dirty, feel free to update it and share your enhancements (for example there is zero control on the date input, so if you write the month without the leading 0, the earth explodes.)