0

How to convert date format in Javascript like

(MM-dd-YYYY) to (YYYY-MM-DD)

please suggest some standard format for conversion

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
  • Look into this question: http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript – Aashray Dec 20 '13 at 06:44
  • this is pretty common question, you should have shown some effort :( – Praveen Dec 20 '13 at 06:46

3 Answers3

0

This should work fine

var str = "01-17-2021";
var arr = str.split("-");
var dateFormatted= arr[2]+"-"+arr[0]+"-"+arr[1];
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
0
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
var newDate =  curr_year  + "-" + curr_month + "-" + curr_date ;
T McKeown
  • 12,971
  • 1
  • 25
  • 32
0

Look at this link. http://jsfiddle.net/9C2p8/

   var start = new Date('10-10-2013');

   var startDate = $.datepicker.formatDate('yy-mm-dd', new Date(start));
   alert(startDate);
Prasath
  • 1,233
  • 2
  • 16
  • 38