Search
Learn
Share

Set date format jQuery Datepicker and use multiple datepickers

Published by Robert Höög on 22 January, 2018
9 views
$(document).ready(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();

$('#datepicker1').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: 'yy-mm-dd'
});
$('#datepicker2').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: 'yy-mm-dd'
});
});

Name the input fields with an ID of "datepicker", like so:
<input type="text" id="datepicker1" name="whatever">

If you want more than one datepicker on the just set the code as "datepicker2" both in the jQuerycode and the second input field:

<input type="text" id="datepicker2" name="whatever">