Date format in Markdown custom widget

Hi there,

I am building a table with all the assigments teachers give theire students. The idea behind this list is that all teachers have access to it and know when they can give students an assignment without overloading them.
I’ve made the table in such a way that these assignments can be seen in the calendar widget. And by clicking on an event (assigment) in the calendar, the teacher can see its details in a widget on the right that I’ve set up as Markdown. So far, everything works as planned. I used Grist’s Proposals & Contract template to make the Markdown template, which looks like this:

### {Materia}
Docente: {Docente}
<span style="font-size:0.8em;">
Clase: **{Clase.Clase}**
Entrega: **{Final}**
Presentación: **{Presentacion}**
con: **{Paginas}**
*<span style="font-size:0.7em;">Obs.: Tarea entregada con {Antelacion} días de antecedencia. 

wich then looks like this:

My only problem is that in the Entrega: {Final} line, which shows the delivery date, is in the YYYY-MM-DD format, and I would like it to show as DD-MM-YYYY.
I’ve changed the Document settings for our country (Paraguay), I’ve changed the configuration of that column in the table, but the variable in Markdown is still showing in the default format.

My question: is it possible to set the date format in the Markdown template?

Another thing: is it possible to remove the Edit button in the Markdown widget from the teachers’ view? They can’t change anything due to access rules, but they can click the button and an error appears when they try to make a change. It would be nice if the button wasn’t there in the first place. it just creates confusion.

I think the best way to achieve that would be to use a separate column. Make it a formula column and set its type to ‘Text’, then use a formula like this one:

def format_as_date(val: or datetime.datetime, include_day: bool=True, formatstring: str=None) -> str:
  if formatstring is None:
    formatstring = ("%d." if include_day else "") + "%m" + ("." if include_day else "/") + "%Y"
    return val.strftime(formatstring)
    # If things aren't working, uncomment the line below to find out why.
    return val

return format_as_date($Your_Actual_Date_Column)

This will take the date from $Your_Actual_Date_Column and turn it into a string, by default using the format “31.01.2024” but you could pass it any other ‘formatstring’ argument (see the Python docs for more info).

Hope it helps!

I will give it a go!

It kind of worked…
It shows the date correctly now:

It shows it with a red background in the table, with no error message:

is this a concern?

Answering my own question:

The red backgound was because I had the column type as Date, once I changed it to Any, the red went away.

All good now.

Thank you very much!

Did you set the type of the ‘Final’ column to ‘Text’? Judging from your screenshots, you probably set it to ‘Date’. That won’t work because my formula turns proper ‘Date’-type data into a mere textual representation. So technically you end up with text data in a ‘Date’ data column, and Grist colours it red because it doesn’t like it. Oh, I see you already solved it. Congrats! :slight_smile:

1 Like