user2061886 user2061886 - 3 months ago 7
Javascript Question

converting yyyy-mm in string format to a month name var javascript

if I had a string like this:

var dte = '2017-07'


how would I convert that to another var with a value of 'July'?

Answer

var dte = '2017-07'
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var another = months[+dte.split('-')[1] - 1]
console.log(another);

Comments