Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the day, month and year with moment.js

2014-07-28

How do I find the month, year and day with moment.js given the date format above?

var check = moment(n.entry.date_entered).format("YYYY/MM/DD"); var month = check.getUTCMonth(); var day = check.entry.date_entered.getUTCDate(); var year = check.entry.date_entered.getUTCFullYear(); 
like image 537
vini Avatar asked Jul 28 '14 13:07

vini


People also ask

How do you find the month in a moment?

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

How do you find the day from date in a 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). format("dddd"); console.

How do you find the year from a date in a moment?

Here, Creating a basic example of how to get year from date in moment js. Here, i will give you simple example of jquery moment js get year from date using format('YYYY'). Tags : jQuery.


1 Answers

Just try with:

var check = moment(n.entry.date_entered, 'YYYY/MM/DD');  var month = check.format('M'); var day   = check.format('D'); var year  = check.format('YYYY'); 

JSFiddle

like image 162
hsz Avatar answered Oct 08 '22 18:10

hsz