How to convert a date that is in the format yyyy-mm-dd. For example: 2014-12-12 to Dec 12 2014?

var oldDate = '2013-4-18';
var newDate = null;
var arrayMonth = ['Jan', 'Feb', 'Mar', 'Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Des'];
var help = oldDate.split('-');
newDate = arrayMonth[help[1] - 1] + " " + help[2] + " " + help[0];
console.log(newDate);

Try this following script to convert date to yyyy-mm-dd to mmm dd yyyy..

function formatDate(d)
{
    var date = new Date(d);

    var month = new Array();
    month[0] = "Jan";
    month[1] = "Feb";
    month[2] = "Mar";
    month[3] = "Apr";
    month[4] = "May";
    month[5] = "Jun";
    month[6] = "Jul";
    month[7] = "Aug";
    month[8] = "Sept";
    month[9] = "Oct";
    month[10] = "Nov";
    month[11] = "Dec";

    day = date.getDate();
    return month[date.getMonth()] +" "+day + " " + date.getFullYear();
}
date_response = formatDate(' 2014-12-12');
console.log(date_response);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.