i want to ask about convert datetimepicker to datepicker, i have value datetime, and i want to convert date ? how to convert that? this is my value
2013-11-29 10:12 to 29-11-2013
Thanks.
i want to ask about convert datetimepicker to datepicker, i have value datetime, and i want to convert date ? how to convert that? this is my value
2013-11-29 10:12 to 29-11-2013
Thanks.
var date = new Date("2013-11-29 10:12"); //parse the date
var mon = date.getMonth() + 1;
console.log(date.getDate() + '-' + mon + '-' + date.getFullYear()); //returns 29-11-2013
Since @RobG mentioned about browser compatibility, here is another approach
var date = "2013-11-29 10:12";
var d = date.substring(0, 10).split("-");
console.log(d[2] + "-" + d[1] +"-" + d[0]); //returns 29-11-2013
If the value is always provided as a string, you can adjust the format using:
// Reformat 2013-11-29 10:12 to 29-11-2013
function formatDateString(s) {
var s = s.split(/\D/);
return s[2] + '-' + s[1] + '-' + s[0];
}
Note that this format may be misinterpreted by those who expect dates in month/day/year format.
If you just want the string, just get the day/month/year substrings you need with substr
or substring
, if you want the a javascript object, you can use Date
.