In modal unable to get chosen date in dd/mm/yyyy format

1.2k views Asked by At

I am using admin lte date picker its by default date format is mm/dd/yyyy when i change date into dd/mm/yyyy format I unable to get right selected date,

Here js code that is used to call datepicker

$(function () {
    $('#datepicker').datepicker({
        format : 'dd/mm/yyyy',
        autoclose: true
    });
})

I always getting this date 01/01/0001 12:00:00 A.M.on changing format, How can i get correct date in dd/mm/yyyy format?

2

There are 2 answers

0
nikli On

Don't write yyyy, write only yy for year and not format use dateFormat http://api.jqueryui.com/datepicker/#utility-formatDate

or you can do it by attribute data-inputmask="'alias': 'mm/dd/yyyy'"

<input class="form-control validuser" id="datepicker" name="DOB" placeholder="Date Of Birth" type="text"  data-inputmask="'alias': 'mm/dd/yyyy'" data-mask=""/>
3
VIGNESH ARUNACHALAM On

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery Datepicker</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker({ dateFormat: 'dd/mm/yy' });
  } );
  </script>
</head>
<body>
 
<p>Date: <input type="text" id="datepicker"></p>
 
 
</body>
</html>

Inside the JQuery script code just paste the code.

$( "#datepicker" ).datepicker({ dateFormat: 'dd/mm/yy' });

For more Details refer this link:

date-formats