Convert mm/dd/yyyy to dd/MMM/yyy format in Javascript

Convert mm/dd/yyyy to dd/MMM/yyy format in JavaScript


Here I am writing JavaScript method to convert mm/dd/yyyy to dd/MMM/yyy of date format, it is frequently used while you are working in JavaScript or JQuery.


There are many scenarios where you need to change the date format, this will help to change one type of change the format of date


var dateParts=dateString.split(‘/’);
var monthNames = “,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC”.split(“,”);
return “” + dateParts[1] + “-” + monthNames[parseInt(dateParts[0])] + “-” + dateParts[2];

Here if you passing date format (11/30/2016), you will get result in 30-NOV-2016 Format.


You can write a code to do just reverse of same thing like.


var dateParts=dateString.split(‘-‘);
var monthNames = “,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC”.split(“,”);
var monthname = monthNames.indexOf(dateParts[1]);
var returnvar= “” + monthname + “/” + dateParts[0] + “/” + dateParts[2];
return returnvar;


Above function will take 30-NOV-2016 and will return 11/30/2016 format of date.



Hope this will be useful for you.



Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 9 =

Tech Contents © 2016