Reputation: 1634
I am trying to set the format of a jQuery datepicker to dd-mm-yy
, and log it to the console when I click a button. The code I have is:
$('#ajaxButton').click(function () {
var date = $('#datepicker').datepicker({
dateFormat: "dd-mm-yy"
}).val();
console.log(date);
});
The date
09/01/2016
is being logged to the console
I can't figure out why, can anyone help?
Upvotes: 0
Views: 115
Reputation: 4309
Below code will give you date in your given format :
$('#ajaxButton').click(function () {
console.log(date.val());
});
var date = $('#datepicker').datepicker({
dateFormat: "dd-mm-yy"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<input type="text" id="datepicker">
<input type="button" id="ajaxButton" value="click"/>
Upvotes: 2