Home » Jquery » laravel – Disabling past dates in datetimepicker jQuery

laravel – Disabling past dates in datetimepicker jQuery

Posted by: admin February 22, 2020 Leave a comment

Questions:

In my application, I have two dates field, start date, and end date. And I wanted to disable the past dates when selecting a date. So for that, I added these code lines.

 var dateToday = new Date();    
$('#start_date, #end_date').datetimepicker({
        format: 'MM/DD/YYYY',
        minDate: dateToday
    }); 

This works fine when creating a post. But when going to edit view, past dates are not set to the date fields. If dates greater than today only it’s showing the date. But I want to show the past dates also in the date fields when trying to edit but not to allow to select a past date (It is working with current code) but how to keep showing the past dates also in date fields when trying to edit.

Also, I have added the same code lines to the edit view also. How to keep showing the date whatever it is greater than or less than today when trying to edit?

How to&Answer: