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.

4
  • Is it jQuery UI datepicker ? Commented Mar 12, 2018 at 5:54
  • which datepicker? Commented Mar 12, 2018 at 5:55
  • Yeah. jQuery datepicker Commented Mar 12, 2018 at 6:06
  • 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. Commented Apr 5, 2018 at 9:29

3 Answers 3

0

Your code should look like this:

$('.datepicker').datepicker({dateFormat: "dd-mm-yy", maxDate: 0});
Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

Try this for future date disabling.

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

Comments

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">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.