I need to convert a date from dd/mm/yyyy to yyyy/mm/dd. I am getting the input from a text box in dd/mm/yyyy format.When i try to convert it to yyyy/mm/dd i got the error invalid date.How can i convert it properly.
Here's the snippet I found working
date="21/01/2015";
var newdate = date.split("/").reverse().join("-");
console.log(newdate)
Try this
var date= '21/01/2015';
var d=new Date(date.split("/").reverse().join("-"));
var dd=d.getDate();
var mm=d.getMonth()+1;
var yy=d.getFullYear();
var newdate=yy+"/"+mm+"/"+dd;
Working Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With