-2

I have this date in this format.

   var str="2019-08-19";(year/month/date)
   var parts =str.split('-');
   var day =parseInt(parts[2],10);

I need to figure out as which day was 19th (Monday/Tuesday /...) . What i tried doing was splitting the given date but that could only give the information such as 19 etc

jammy
  • 857
  • 2
  • 18
  • 34
  • 2
    Possible duplicate of [Day Name from Date in JS](https://stackoverflow.com/questions/24998624/day-name-from-date-in-js) – Hassan Imam Aug 22 '19 at 07:08
  • `new Date('2019-08-19').getDay()` 0 - Sunday -> 6 - Saturday. See docs (here)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay] – phuzi Aug 22 '19 at 07:14

2 Answers2

1

You can simply do this

  var d = new Date( "2019-08-19");
  var weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

  var n = weekday[d.getDay()];
Masuk Helal Anik
  • 2,155
  • 21
  • 29
0

Following example will help you.

var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

var d = new Date("2019-08-18");  

var dayName = days[d.getDay()];

document.getElementById("myId").innerHTML = dayName;