142

I'm using jquery and moment.js for a custom calendar.

I have a date object in a variable myDate like :

 Object { date="2014-12-23 14:00:00", timezone_type=3, timezone="Europe/Paris"}

I want, using moment.js (or not) get the day name of this date, in my example i need to get : tuesday

Ideas ? Thanks

3
  • 4
    moment().format('dddd'); should work Commented Dec 27, 2014 at 16:14
  • already tried, if i use moment(mydate).format('dddd') i have invalid date in error Commented Dec 27, 2014 at 16:15
  • 1
    probably is mydate your problem Commented Dec 27, 2014 at 16:16

3 Answers 3

266

With moment you can parse the date string you have:

var dt = moment(myDate.date, "YYYY-MM-DD HH:mm:ss")

That's for UTC, you'll have to convert the time zone from that point if you so desire.

Then you can get the day of the week:

dt.format('dddd');

And you can get the 3 letter format weekday by

dt.format('dddd').substring(0,3)
1
  • 2
    There are so many non-working answers out there. This is the one that works! Commented Jul 31, 2016 at 16:42
81

code

var mydate = "2017-06-28T00:00:00";
var weekDayName =  moment(mydate).format('dddd');
console.log(weekDayName);

mydate is the input date. The variable weekDayName get the name of the day. Here the output is

Output

Wednesday

var mydate = "2017-08-30T00:00:00";
console.log(moment(mydate).format('dddd')); // Wednesday
console.log(moment(mydate).format('ddd'));  // Wed
console.log('Day in number[0,1,2,3,4,5,6]: '+moment(mydate).format('d')); // Day in number[0,1,2,3,4,5,6]: 3
console.log(moment(mydate).format('MMM'));  // Aug
console.log(moment(mydate).format('MMMM'));  // August
<script src="https://momentjs.com/downloads/moment.js"></script>

10
var mydate = "2017-06-28T00:00:00";
var weekDayName =  moment(mydate).format('ddd');
console.log(weekDayName);

Result: Wed

var mydate = "2017-06-28T00:00:00";
var weekDayName =  moment(mydate).format('dddd');
console.log(weekDayName);

Result: Wednesday

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