Lara Ch Lara Ch - 7 months ago 23
Javascript Question

Using jQuery to change date format into d-m-y

I need to change a date format taken from HTML date input and added into a text box. Currently if I am adding date as: 04-26-2016 it will be added to text box as 2016-04-26.

But what I need is to add it into my text box as : 26-04-2016.
Is their any way using jquery ?

$(document).ready(function()
{
//onee is date input:
$("#onee").on('change', function()
{
var val = $("#onee").val();
$('#one').val($('#one').val() + "- Date:" + val);
});
});

Answer

Set a's value to your textbox.

var a=$.datepicker.formatDate( "dd-mm-yy", new Date("2016-04-26"));

console.log(a);

Output: "26-04-2016"

Comments