I have a date string such as: 1-Ene-2017
, the case is also presented that is as follows: 28-Ene-2017
, what I try to do is get the part of the month's chain that is: Ene
.
So far I have not been able to get the chain I want, this is what I tried:
function formatDate(date) {
var MonthName=["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"];
var MonthName2=["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
alert("" + date.substring(date.indexOf('-') + 1, 6));
var mes = "";
for(i=0; i<12; i++) {
if(date.substring(date.indexOf('-') + 1, 6) == MonthName[i]) {
mes = MonthName2[i];
}
}
alert("MES: " + mes);
}
formatDate('28-Ene-2017');
formatDate('1-Ene-2017');
They will have some idea of how to get the chain I want.