Converting dates in Tiddlywiki

Is there a trick in TW to convert dates from an arbitrary format to a desired format?
Like from dd.mm.yyyy to yyyy0mm0dd ?

What do you mean by “trick”?

1 Like

There are certain standardized date formats that can be parsed using my TiddlyTools ParseDate custom filter operator (see TiddlyTools/Time/ParseDate.js and TiddlyTools/Time/Info)

The input format for this custom filter operator can be either a TWCore 8-digit date stamp (YYYYMMDD) or 17-digit datetime stamp (YYYYMMDDhhmmssxxx) or any text that is recognized as a Javascript Date() object that conforms to ISO8601 or RFC2822 standards.

The output uses TWCore standard DateFormat codes. Note that inputs are ALWAYS assumed to be UTC+0 dates (i.e., no timezone offset = GMT). To work with local timezone inputs, the output format needs to include the [UTC] prefix. This will prevent automatic timezone adjustment from being performed.

However, dates such as “dd.mm.yyyy” are NOT included in any of those standards, so you will need to write custom wikitext code to convert them yourself. Something like this:

<$let input="07.13.2025">
<$let output={{{
    [<input>split[.]nth[3]] [<input>split[.]nth[2]pad[2]] [<input>split[.]nth[1]pad[2]]
   +[join[]] }}}>

Notes:

  • split[.] separates the parts of the date at the “.” character.
  • After splitting, nth[3] is the year number, nth[2] is the month number, nth[1] is the day number
  • pad[2] ensures that month and day numbers are zero-padded to 2 digits
  • Then, join the results to create the output text

-e

4 Likes

Hi Mario, good point… trick may not be the best word. But there are those moments, when I find out that something I made a clumpsy workaround could have been done in one magic line .

A more generic approach is to convert any particular date to the tiddlywiki timestamp date YYYY0MM0DD0hh0mm0ss0xxx (observe the use of 0), then the you can use the format operator to output in any wonderful date output format:date[DDth MMM YYYY]

1 Like

I thought of something like this when I wrote trick… but how do I convert dates to the timestamp format?

One last question: How can I check whether a title matches YYYY0MM0DD

From any format to the timestamp format depends of course on the input format but you can simply follow a pattern like erics where he splits the parts and joins them back.

  • But this time ensure each value is “zero filled”, to do that you may need to make use of the pad operator.
  • Another trick is to use split[] with no parameter to split a string into characters if you done have helpful delimiters such a space, . or -.
  • If you dont have info eg the milliseconds just fill with spaces.
  • Remember to try and keep dates and times in UTC

I am quite busy and on the road for the next 12 hours so can’t do it now but if we built a list of common input date/time forms I would be happy to write a set of format conversions to the tiddlywiki time start. Once familular with this method its quite easy to convert any format.

Depending on the dates a string starting with 20, 8 chars long, max 12 months, max 31 days but how could you have titles when you dont know they are dates?

1 Like