Q:

Jquery UI, use custom or specific date format

I have two datepickers input in my form using Jquery UI's Datepicker. I need help formatting the date into my own specific format. I declared two variables for each datepicker's ID like this .datepicker({ dateFormat: 'dd/mmm/yyyy' }).val();, but looks like i'm doing it wrong.

var date2 = $('#datepicker2').datepicker({
  dateFormat: 'dd/mmm/yyyy'
}).val();
var date3 = $('#datepicker3').datepicker({
  dateFormat: 'dd/mmm/yyyy'
}).val();

$(function() {
  $("#datepicker2").datepicker();
});

$(function() {
  $("#datepicker3").datepicker();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
Input Data Date:
<input type="text" class="form-control" name="p2" id="datepicker2"><br> 
Birth Date:
<input type="text" class="form-control" name="p2" id="datepicker3"><br>

When i choose a date, what i got is mm/dd/yyy. Can anyone help me, please?

A:

You are not mentioning what your specific format is
You need to check formatDate
Here is an example

$(function() {
  $("#datepicker2").datepicker({
    onSelect: function(dateText) {
     console.log("Selected date: " + dateText + "; input's current value: " + 
     $.datepicker.formatDate("dd M yy", new Date(this.value)));
    }
  });
  $("#datepicker3").datepicker({
    dateFormat: 'dd-mm-yy',
    onSelect: function(dateText) {
      console.log("Selected birth date: " + dateText + "; input's current value: " + this.value);
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
Input Data Date:
<input type="text" class="form-control" name="p2" id="datepicker2"><br> 
Birth Date:
<input type="text" class="form-control" name="p2" id="datepicker3"><br>

