1

Could you please tell me that, how can I translate/detecting the following date format 2016-04-29 and get the week name in pure JavaScript or jQuery? i.e Monday, Tuesday, Wednesday

Thanks in advance.

Ali Mamedov
  • 5,116
  • 3
  • 33
  • 47
FR STAR
  • 662
  • 4
  • 24
  • 50

2 Answers2

1

The day of the week:

var 
    d = new Date('2016-04-29'); // April 29, 2016,
    days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

days[d.getDay()]; // "Friday"
Ali Mamedov
  • 5,116
  • 3
  • 33
  • 47
  • No, no ,no ,no. Just use the standard javascript Date class. No need for arrays or an extra library. See my answer: stackoverflow.com/a/50293232/760777 – RWC May 11 '18 at 13:38
0

If you are open for libraries, try moment.js

alert(moment().format("dddd"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
Rajesh
  • 24,354
  • 5
  • 48
  • 79