Hi folks. I am trying to format a date field in a repeater. I got the code straight from a post Wix published ( https://support.wix.com/en/article/using-wix-code-to-format-dates) but support team won't help as I am "custom coding". On the surface it seems the code should work, but it's not. My first inclination is that it has something to do with being within a repeater. The URL for my dev site is:
https://danceconnectionpcfl.wixsite.com/dcdev/team-events
Can someone guide me here? If I link the datestamp field directly, my date comes back like " Sun Nov 18 2018 13:00:00 GMT-0500 (Eastern Standard Time) ". I don't need all that, and I don't want to confuse any site visitors so I need it to look like "10/18/2018 1:00PM".
When I unlink the field to make my code active and preview the page, I get this JavaScript error:
TypeError: Cannot read property 'event_date' of null
My code as currently stands:
$w.onReady(function () { // Get the date from the date field of the current item const date = $w("#dataset1").getCurrentItem().event_date; // Set the text element to display the date using the user's settings $w("#text21").text = date.toLocaleDateString() });
Thanks in advance!!
I have a code that works for items but it does not work on repeaters, if someone can adapt it to work on repeaters let me know, thanks.
var options = { year: 'numeric', month: 'short', day: 'numeric', weekday: 'long' }; $w.onReady(function () { // Get the date from the date field of the current item const date = $w("#dynamicDataset").getCurrentItem()._createdDate; // Set the text element to display the date using the user's settings const option = { day: "numeric", year: "numeric", month: "short", weekday: "long" }; // Sets the property of the text element to be a string representing today's date in US English $w("#text15").text = date.toLocaleDateString("pt-BR", options); });
Can you post the corrected code? I have the same issue.
Nevermind, I came across another post that solved this issue. Thanks!!