user3386779 user3386779 - 1 month ago 14
Javascript Question

How to reverse date format yyyy-mm-dd using javascript/jquery?

I want to change the date for of data which is in format

2016-10-15
to
d-m-yy
format in jquery as
15-10-2016
.I tried and console the output it shows
2016-10-15
.I caught this result in jquery ajax page which is fetched from database.

$.each(req,function(i,item){
var val=$.format.date(req[i].from_date, "dd/MMM/yyyy");
console.log(val); //'2016-10-15'
});

Answer

You can do this work use native javascript functions. Use .split() to split date by - delimiter into array and invert array using .reverse() and convert array to sting using .join()

var date = "2016-10-15";
date = date.split("-").reverse().join("-");
console.log(date);