user2061886 user2061886 - 1 year ago 63
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 Source

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]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download