I’m new to Wix code and am not very well versed in JavaScript. I’ve also read all the other posts on this topic and still cant quite figure this out. I’m trying to change the date format on a repeater but am having some trouble. I would like the date to displays like this:
August 18, 2018
I tried using a function to change the month format in conjunction with some other code to get rid of the time information… but I can’t seem to get it to work haha. My database is named ‘Articles’, and the text box that displays the date information on the repeater is named ‘text70’ Any and all help would be greatly appreciated. I love Wix Code… this is just all very new to me!
$w.onReady(function () {
$w(“#Articles”).onReady( () => {
$w(“#repeater2”).forEachItem( ($w) => {
function formatDate(date) {
const monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"];
let day = date.getDate();
let monthIndex = date.getMonth();
let year = date.getFullYear();
return monthNames[monthIndex] + ' ' + day + ', ' + year; }
let today = new Date();
let str = formatDate(today);
console.log(str);
const OldDate = $w("#text70").text;
const NewDate = formatDate(OldDate);
$w('#text70').text = NewDate;
console.log('Time removed from Date/Time Stamp: New Date ' + NewDate);
});
});