jQuery datepicker set default value to first day and last day

jQuery Used:

jQuery v1.12.4

Current Date:

09 December 2019


I have this two blank input field

Wanted Result:

The first blank input is filled with first day of date and the last input is filled with last day of date like image below:

Code has been wrote:

<input class="date" name="dateFrom" id="dateFrom" /> - <input class="date" name="dateTo"   id="dateTo" />
        dateFormat: 'dd-mm-yy',


How to do that … ?


Add this code

  var d = new Date();
  var currMonth = d.getMonth();
  var currYear = d.getFullYear();
  var startDate = new Date(currYear, currMonth, 1);
  var lastDate= new Date(currYear, currMonth + 1, 0);

  jQuery( "#dateFrom" ).datepicker( "setDate", startDate );
  jQuery( "#dateTo" ).datepicker( "setDate", lastDate );

Thanks for reading

You may also like...

Leave a Reply

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