0

I want the dates to be in dd-mm-yyyy format and have to block future dates from selection.

I am using the following code:

<script>
$( function() {
$( ".datepicker" ).datepicker({dateFormat: "dd-mm-yy"});
$( ".datepicker" ).datepicker({maxDate: "+0D" });
        } );
</script>

But only the first line in the function works; i.e. date is in dd-mm-yyyy but the disabling of future dates is not achieved.

Sinto
  • 3,915
  • 11
  • 36
  • 70
Ace
  • 13
  • 4

3 Answers3

0

Try this for future date disabling.

$(function() {
$( ".datepicker" ).datepicker({  
dateFormat: "dd-mm-yy",
maxDate: new Date() });});
Robert
  • 147
  • 9
0

You can do that by using below codes,

$("#datepicker").datepicker({
  dateFormat: 'dd-mm-yy',
  maxDate: '0'
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<link href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Date: <input id="datepicker" type="text">
Sinto
  • 3,915
  • 11
  • 36
  • 70
0

Your code should look like this:

$('.datepicker').datepicker({dateFormat: "dd-mm-yy", maxDate: 0});
Alex
  • 2,707
  • 4
  • 29
  • 42
  • Thank you Alex. Now I have another field in the same webpage where datepicker has to be in MM-YYYY format. The system should not allow future month-year combinations. Any suggestions and code snippets will be highly appreciated. – Ace Apr 05 '18 at 09:12