3

I have a format for a date like so 08/11/2015 which is mm/dd/yyyy

Is there a way to get my date set 08/11/2015 and find out what the day name is (ex: Monday, Tuesday, etc) in jQuery?

0

5 Answers 5

15

With javascript this would be the way:

var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

var a = new Date('08/11/2015');
alert(weekday[a.getDay()]);
3
  • Why it is giving wrong output for Date: 28/03/2017. This ans shows Wednesday whereas its Tuesday??? @baao May 2, 2017 at 6:43
  • After changing the date format to MM/dd/yyyy ,it is giving right result. May 2, 2017 at 7:07
  • Works perfectly. Jan 28, 2019 at 11:33
2

'date' is not a concept in jQuery, but it is in vanilla javascript.

You can do this:

var d = new Date('08/11/2015')
d.getDay(); 

getDay() will return an integer from 0 (Sunday) to 6 (Saturday) which you can then map onto a string for that day of the week.

1

I've never used jquery or javascript before, but a quick trip to an interpreter and the documentation led me to this...

js> myDate = new Date('08/11/2015')
Tue Aug 11 2015 00:00:00 GMT-0700 (Pacific Daylight Time)
js> 

so if you just pass your timestamp to Date() and then use some pattern matching or string manipulation on the first part of the result, you can find out which day it was. Hope that helps!

1
  • Haha sorry for the repeat answer..apparently I should have refreshed my page before I posted Aug 11, 2015 at 22:33
0

You have to enumerate your own values:

var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var d = new Date();
var n = weekday[d.getDay()];
0

You can also use moment.js:

moment("2010-10-20 4:30", "dddd");

I know that it is an external dependencies, however it helps when dealing wienter code hereth different locales.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.