Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment.js get day name from date

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

like image 585
Clément Andraud Avatar asked Dec 27 '14 16:12

Clément Andraud


People also ask

How do you get the day name from the moment?

To get day name from date with Moment. js and JavaScript, we can use the format method. const myDate = "2022-06-28T00:00:00"; const weekDayName = moment(myDate).

How do I get weekday from date in moment?

Syntax. moment(). weekday(Number); moment(). weekday();

How do you find the day of the month in a moment?

daysInMonth() Function. The moment(). daysInMonth() function is used to get the number of days in month of a particular month in Node.

How do I get the day name from date in react native?

Getting the day name from a date: function getDayName(dateStr, locale) { var date = new Date(dateStr); return date. toLocaleDateString(locale, { weekday: 'long' }); } var dateStr = '05/23/2014'; var day = getDayName(dateStr, "nl-NL"); // Gives back 'Vrijdag' which is Dutch for Friday.


2 Answers

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'); 
like image 92
Paul Avatar answered Sep 28 '22 14:09

Paul


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>
like image 39
Deepu Reghunath Avatar answered Sep 28 '22 15:09

Deepu Reghunath