In web development, taking date input from user is commonly occurs. The jQuery Date picker provides an excellent user interface and user experience. It also provides many functionalities like start date, end date, format date for user display or more.
While taking date input sometimes we need to skip some dates or need to force user to select date except some date days or dates like weekends or holidays. Without date picker, we need to validate it against user input but a date picker provides functionality to disable some dates while taking user input easily.
For example, we are creating HRMS or a school application which has a leave module. So it is normal to take leave on working days only. The user can not apply for leave on weekends. In this example, we will disable weekends from datepicker instance using jQuery.
In the above code, we have used libraries like Bootstrap, jquery-ui, and jquery and defined single input with id as datepicker. Then in the document ready method, we initialized jQuery datepicker. While initializing jQuery Datepicker, we applied beforeShowDay property and its value for disabling weekends.
When someone tries to select a date then it will show weekends disabled and user can not select Saturday or Sunday. Below is a simple output image for the above example.
In this article, we have created simple date input and disabled weekends for that input. There are many options or properties which can be useful with datepicker.