How to transform a date input format into an output format?

Is it possible, after entering
20241020
an output of
Sunday, October 20, 2024 in bold
to receive?
It should be the first entry in the first line of a diary.

Thank you
Greetings

Sure, it’s possible. If you are looking to get a solution that achieves this, could you change the title so that it is in the form of a question, and move this post to the Questions category? See How to post in the Questions category for tips.

Here’s one solution for it, but it will trigger on any 8 numbers that are in a row which could cause problems.

#show regex("\d{8}"): it => {
  let txt = it.text
  let date = datetime(
    year: int(txt.slice(0, count: 4)),
    month: int(txt.slice(4, count: 2)),
    day: int(txt.slice(6, count: 2))
  )
  strong(date.display("[weekday] [month repr:long] [day], [year]"))
}

On 20241020 something happened.  20220115 also had something happen.
Output

image

1 Like

You could also create a function that you call every time you want to convert a timestamp. That way, the problem mentioned in @gezepi’s solution doesn’t happen.

#let timestamp(t) = {
  let txt = str(t)
  let date = datetime(
    year: int(txt.slice(0, count: 4)),
    month: int(txt.slice(4, count: 2)),
    day: int(txt.slice(6, count: 2))
  )
  strong(date.display("[weekday] [month repr:long] [day], [year]"))
}
  
On #timestamp(20241020) something happened.  #timestamp("20220115") also had something happen.

Thank you for your answers!
It works fine, but how can I change the language? (see Questions Categorie)

These packages may help: