Formatdate markdown content

I have a markdown content in Canvas like this:

{{#each rows}}
### {{date}} ###

where date is, for example:


how can i format this date (d/m/y hh:mm) and set the local timezone?


@accateo I believe setting that date on canvas linked to the current browser local timezone is not possible yet. The best you can do is using formatdateto format the date and math operations to add or substract on the date itself. For example the example below with subtract an hour on the date being shown:

date | math "subtract(value, 3600000)" | formatdate format="MMMM YYYY"

More information about this issue can be found at [Canvas] Display timestamp in the browser's timezone · Issue #33959 · elastic/kibana · GitHub

I have this...

@accateo please look into your expression editor. You are probably not exposing date param in the data that reaches the markdown function

I don't understand the problem...


You are receiving that error because you are passing the output of the markdown function and passing that into the math function, which doesn't work.

I think to accomplish what you are looking for, you should add a new column to your essql result that will contain the formatted date.

You can do that by doing something like

| essql ....
| mapColumn name="formatted_date" expression={getCell "date" | math "subtract(value, 3600000)" |  formatdate format="MMM DD YYYY hh:mm:ss z"}
| markdown "{{#each rows}} {{formatted_date}} {{/each}}

The bug with format date is that it takes in what it assumes is a utc date, creates a localized date, but then assumes that localized date is utc. So, if you are UTC +5, and you give it a UTC time of 04:00:00, it's incorrectly going to format that to 09:00:00, so you would need to subtract those 5 hours off of the input date to get it formatted correctly, like @tiagocosta mentioned above.

Hope that helps.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.