If I have a date like 2014/07/28, how do I get the output to be July?
Asked
Active
Viewed 1,063 times
-2
-
1[Self-answer](https://stackoverflow.com/help/self-answer) is encouraged on Stack Overflow. But, please make sure the question hasn't already been asked here. Getting the month name from a date is a very popular topic and has been asked many times. – adiga Oct 23 '20 at 05:26
1 Answers
-1
var myDateVariable= moment("2014-07-28").format("YYYY/MM/DD")
var newDateVariableMonth = moment(moment("2014-07-28").format("YYYY/MM/DD")).format('MMMM');
console.log(myDateVariable);
console.log(newDateVariableMonth);
Output
"2014/07/28"
"July"

Kshitij Zutshi
- 69
- 7
-
`moment(moment("2014-07-28").format("YYYY/MM/DD")).format('MMMM');`??? why not just `moment("2014-07-28").format('MMMM');`? – Jaromanda X Oct 23 '20 at 05:12
-
1
-
Hi All, appreciate your comments. This answer was specific to a project I am doing where in I need to have the date in a specific format for validation. Yes, `moment("2014-07-28").format('MMMM');` and `myDataVariable.format('MMMM')` Both are correct way to do instead. @JaromandaX et all thanks for pointing out. – Kshitij Zutshi Oct 26 '20 at 05:20