0

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);
  });
});
Lara Ch
  • 165
  • 3
  • 12

2 Answers2

2

try this one

var todaydate = new Date("2016-04-26");  //pass val varible in Date(val)
var dd = todaydate .getDate();
var mm = todaydate .getMonth()+1; //January is 0!
var yyyy = todaydate .getFullYear();
if(dd<10){  dd='0'+dd } 
if(mm<10){  mm='0'+mm } 
var date = dd+'-'+mm+'-'+yyyy;
Ajay Kumar
  • 1,314
  • 12
  • 22
2

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"

Shantanu Madane
  • 617
  • 5
  • 14