Simple Date formatting in Repeaters question

I have a repeater set up to show my blog posts with the title and publication date. I connected the information to the dataset and everything is working fine. I just have a formatting preference that I’m not able to set up and would like to know if anyone knows how to do it… I chose to display the date as the short date which looks like this: 04/05/2022. I would like to replace the “/” with a “-”, to make the date be displayed as 04-05-2022. Is that possible through code?

Here’s a screenshot of the repeater and the dataset connection, in which I chose the short date format. And if you look to the repeater itself is how I would like the date to be formatted.

This is how it actually appears in preview:

Any help will be very much appreciated. Thanks!

If it’s OK to present the date based on the UTC time zone (the date changes at 00:00 UTC). Then disconnect the dateText from the dataset , add code like this:

$w.onReady(() => {
$w('#dataset1').onReady(async () => {
    $w('#reapeater1').forEachItem($i, iData) => {
        $i('#dateText').text = iData._publishedDate.toISOString()
        .slice(0, 10).split('-').reverse().join('-');
        })
    })
})

[I changed the answer].

You just have to use .toLocaleDateString() method on the Date object with the format location you want, I assume you are Brazilian, so ‘pt-BR’ .

You have to disconnect the dateText field from the dataset as mentioned above by J.D. , and manually connect to the repeater through code, like so:

$w.onReady(() => {
  $w('#dataset1').onReady(async () => {
    $w('#reapeater1').onItemReady($item, itemData) => {
      $item('#dateText').text = itemData._publishedDate.toLocaleDateString('pt-BR')
    })
  })
})

Hi Bruno,

I tried your suggestion, but I’m having some issue with the code. Maybe I did something wrong.

But I’m not sure if this alone would be the solution I’m looking for, it doesn’t have to do with the order DDMMYYYY or MMDDYYYY it has to do with the symbol that separates each part of the date, one is a “dash” (the one I want) so it would show DD-MM-YYYY instead of the other which is a “slash” (what is currently showing) DD/MM/YYYY.

Hi JD.

I’m getting this issue on the code:

any insight? thank you

@buenok you are missing a pair of parentheses arround the callback arguments: .onItemReady( ( $item, itemData ) => { …rest of the code }

($item, itemData) =>

About the slash Vs dash question, it is a Locale option, in USA it is common using the dash as a date separator. In BR it is common to use the slash separator for dates.