Reputation: 11
aData[8]
is the column number which shows date in dd-mm-yyyy
format.
I want to change it to yyyy-mm-dd
format for validation purpose.
var dueDate = new Date(aData[8]);
console.log(aData[8]);
var dt_to = $.datepicker.formatDate('dd-mm-yy', new Date(dueDate));
var dueDatetimestamp = dt_to.getTime();
Upvotes: 1
Views: 942
Reputation: 1995
Personnally, I'm using jQuery.format.date(value,'date-format')
. But this is a jQuery's plugin available at https://github.com/phstc/jquery-dateFormat
Very simple to use (example from Github) :
<script>
document.write($.format.date("2009-12-18 10:54:50.546", "Test: dd/MM/yyyy"));
document.write($.format.date("Wed Jan 13 10:43:41 CET 2010", "dd~MM~yyyy"));
</script>
Upvotes: 0
Reputation: 4906
you can use date.js to achieve :
var dateAr = '2014-01-06'.split('-');
var newDate = dateAr[0] + '-' + dateAr[1] + '-' + dateAr[2];
Upvotes: 0
Reputation: 23816
Consider this:
var str = '13-02-2014';//your format dd-mm-yyyy
var newar = str.split('-');
var tempDate = newar[2] + '-' + newar[1] + '-' + newar[0];
var d = new Date(tempDate);
console.log(d);//date object
console.log(tempDate);//new format yyyy-mm-dd
Upvotes: 0
Reputation: 3080
I like to use moment.js to manipulate dates.
You could do something like that with it:
moment("13-08-2014", "DD-mm-YYYY").format("YYYY-mm-DD")
Upvotes: 1