Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
});
like image 992
user3386779 Avatar asked Oct 25 '16 05:10

user3386779


1 Answers

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);
like image 188
Mohammad Avatar answered Oct 13 '22 19:10

Mohammad