Disable Past Dates Or Upcoming Dates In PHP Datepicker

No votes yet.
Please wait...

Hello Guys,

Thanks for liking our tutorials ,we are getting a lots of comments and appreciation from you guys which means a lot to us .Taking our earlier tutorial  JQUERY DATEPICKER RESTRICT DATES IN SECOND DATE FIELD BASED ON SELECTED DATE IN FIRST DATE FIELD as a refrence , we received a lots of comments on it where our fellow developers have situations where they want to disable past dates or upcoming dates from Datepicker.

So today we are here with a Snippet in which we will learn how to disable past dates or upcoming dates in PHP Datepicker.

Disable Past Dates:
We can easily disable old dates from datepicker by using Jquery function and setting minimum date to today

1
2
3
4
5
6
7
<script>
$( function() {
$( "#shootdate" ).datepicker({
minDate: 0
});
      });
</script>

Disable Upcoming Dates:
We can easily disable upcoming dates from datepicker by using Jquery function and setting minimum date to today

1
2
3
4
5
6
7
<script>
$( function() {
$( "#upcoming" ).datepicker({
maxDate: 0
});
      });
</script>

Whole Script Goes Like This:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
            $( function() {
                $( "#shootdate" ).datepicker({
                    minDate: 0
                });

                                $( "#upcoming" ).datepicker({
                    maxDate: 0
                });
            });
        </script>
<div align="center">
<h1>Demo By PHPHURDLES</h1>
</div>
<div>
<h2 align="center">Disable Upcoming Dates in Datepicker</h2>
<div align="center"><label for="shootdate">Desired Date:</label>
<input id="upcoming" title="Choose your desired date" name="upcoming" required="" type="text" /></div>
</div>
<div>
<h2 align="center">Disable Previous Dates in Datepicker</h2>
<div align="center"><label for="shootdate">Desired Date:</label>
<input id="shootdate" title="Choose your desired date" name="shootdate" required="" type="text" /></div>
</div>

Run Code Snippet

That’s how we can diasable past or upcoming dates from datepicker
Hope this tutorial will help our those fellow developers which are facing problem in this.
and guys feel free to share your problems with us,comment us or mail us at phphurdle@gmail.com.You can also share your experiences in our new section write for us where you can write your own tutorials and can help your fellows.
Because Hurdles aren’t really Hurdles

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *