1

I searched stackoverflow but did not find a solution to my problem.

I have a specific date say 2014-05-20 and I want to get the Day of the week for the mentioned date.

I tried the following

var date = new Date();
console.log(date.getDay());

But this return the Current Day. What I require is the day based on the given date!

I also tried

var givendate = '2014-05-20';
new Date(givendate)

But the above does not generate anything.

Ashik Basheer
  • 1,531
  • 3
  • 16
  • 36

2 Answers2

1

Your question both code you combine and check answer is get on yourself without my answer still i show you code,

Check this Demo jsFiddle

JavaScript

var givendate = '2014-05-20';
var date = new Date(givendate);
console.log(date.getDay());

Console log

2 
Community
  • 1
  • 1
Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76
1

you may try

var date = new Date(2014, 05, 20).getDay(); // Date(year, month, date)
console.log(date);

you will get integer 0 for sunday - 6 for saturday

BenMorel
  • 34,448
  • 50
  • 182
  • 322
kp singh
  • 1,430
  • 8
  • 21