Home / GitHub Page

1.0.165 timestamp formatting in new template

Hi,

I tried to get the correct timestamp format

This works:

{{#custom_datetime}}MMMM dddd{{/custom_datetime}}

and gives:

August Sunday

But ideally, I’d like to get this:

Sonntag, 18. August 2019 16:43 Uhr (6 Tage zuvor)

Is this possible?

Greetings,

merlinuwe

1 Like

Best I can suggest (through just experimenting with different values) is:

{{#custom_datetime}}dddd, DD. MMMM YYYY HH:mm U\hr{{/custom_datetime}}

You have to escape the “h” in “Uhr” otherwise it inserts an “hour” value.

I can’t see how a date code can give you a value for “x days ago”

1 Like

Joplin simply passes the date format to moment.js for rendering. As dpoulton has said, I don’t think an x days ago template will work, but otherwise everything else should be okay.
That said, it should be possible to create a new template function that would allow “x days ago” using mustache and moment.

The relavent code is in TemplateUtils.js specifically in the view object. I’m sure a pull request would be merged if you added this feature.

@merlinuwe

I have had a play and these appear to be some values you can use to format the date/time however you want it.

Example:

Sunday 18 August 2019 7:35 and 45 seconds pm

Value Output Note
d 0 Day of the week (0-6)
dd Su Day of the week (name abbreviated 2 chars)
ddd Sun Day of the week (name abbreviated 3 chars)
dddd Sunday Day of the week (name full)
D 18 Date (numeric)
Do 18th Date (numeric with suffix)
DD 18 Date (numeric always 2 digits)
DDD 230 Day of the year
w 34 Week of the year
M 8 Month (numeric)
MM 08 Month (numeric always 2 digits)
MMM Aug Month (name abbreviated)
MMMM August Month (name full)
Y 2019 Year (full)
YY 19 Year (abbreviated)
YYYY 2019 Year (full)
h 7 Hour (12 hour clock)
hh 07 Hour (12 hour clock always 2 digits)
H 19 Hour (24 hour clock)
HH 19 Hour (24 hour clock always 2 digits)
m 35 Minutes
mm 35 Minutes (always 2 digits)
s 45 Seconds
ss 45 Seconds (always 2 digits)
a pm am / pm indicator

So

{{#custom_datetime}}dddd, D. MMMM Y HH:mm U\hr{{/custom_datetime}}
Sunday, 18. August 2019 19:35 Uhr

{{#custom_datetime}}dddd, Do MMMM Y h:mm:ssa{{/custom_datetime}}
Sunday, 18th August 2019 7:35:45pm

It looks like moment.js has a .fromNow(); function but I am not a programmer and so I assume from calebjohn’s comment above it would require a new template function to be created to use it.

4 Likes

@dpoulton Thanks for this useful info

From reading the moment.js page referenced above I saw that it allows data to be escaped using square brackets [ ].

I found that this also works within {{#custom_datetime}} so you can create a timestamp “boilerplate” in a template using just one set of {{#custom_datetime}} tags.

For instance:

If you have the multimarkdown table extension enabled, this:

{{#custom_datetime}}[| Created: |]dddd, D MMMM Y HH:mm \hr\s[|||
| :--- | :---: | :--- | :---: |
| Day: |]DDD[| Week: |]w[ |]{{/custom_datetime}}

Automatically creates:

boilerplate

At least it does for me!!

Not overly useful but kinda cool…

I’m going to stop now as I have abused merlinuwe’s thread far too much…

2 Likes

Thank you very much for the clearifications in text and as a reference and the really cool table.

The translation into other languages and “(6 Tage zuvor)” would be nice, to make the content look more professional.

Good point, I just assumed it did that naturally, I’ll make a pull request.

edit: pull request here