if I had a string like this:
var dte = '2017-07'
how would I convert that to another var with a value of 'July'?
if I had a string like this:
var dte = '2017-07'
how would I convert that to another var with a value of 'July'?
Use the split()
function like this:
var dte = "2017-07";
var res = dte.split("-");
Res is an array of each part of the split, so access the month number by typing res[1]
. Then I would compare the number in a switch
-statement and get out the month name.
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);
First you split the string in "yyyy", "-" and "mm". Then you compare the last string, "mm" with paterns that correspond to the correct month. You could do this with 2 string arrays. 1 has the paterns, "01", "02" etc. The other has names, "januari", "februari" etc. Iiterate the for loop over the first array. When you have a match, you know the word you are looking for is in the other array, at the same index.