Showing day of the week in date format

Jorge Batres
Jorge Batres used Ask the Experts™
on
Hi, I have a js script that generates the date format without the day of the week like September 24, 2019, but I need it to display Tuesday, September 24, 2019. Could you please help me edit the script to make that change?

Thank you in advance for your help.

Jorge B.
calendarmain.js
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Hi Jorge,

It would help if you could paste your code to display the date, but easiest solution  should be to add:
var dayOfWeek = new Date().toLocaleDateString('en', {weekday:'long'});
YourDateString = dayOfWeek + ", " + YourDateString

BR,
J

Author

Commented:
I thought I had uploaded the js file on my original question but I edited the question and uploaded the file so it is there now.
Commented:
Hi Jorge,

Should work if you add after line 3 (var monthNames ...) following line:
var dayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

Open in new window


And change the formatDisplayDate function like this:

function formatDisplayDate(str) {
  // getting mm/dd/yyyy~m/dd/yyyy
  arr=str.split("~");
  fmtArr=[];
  for (var i=0;i<arr.length;i++) {
    var parts = arr[i].split("-");
 //   window.console && console.log(parts);
    fmtArr.push(dayNames[(new Date(arr[i])).getDay()] + ", " +monthNames[parts[1]-1]+" "+parts[2]*1+", "+parts[0])
  }
  return fmtArr.join("; ");
}

Open in new window

Try it out and let us know how it works.

BR,
J.

Author

Commented:
Thank you so much, it worked!

Author

Commented:
Thank you very much for your fast response. Your suggestion worked perfectly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial