I want to disable a date which is 24hours from the current timestamp in the date-picker.
For e.g, if the current date-time is 6th June 12:00 PM then the next date i.e 7th June should be disabled till 12:00 PM on the 7th June. I have two dropdowns in the form, one for selecting the date and the other for selecting the time slot which is a time-picker.
So as per the above scenario, if 7th june has time-slots such as 8:00AM-10:00AM, 10:00AM-12:00PM and so on..then it should disable the time slots also accordingly.
I am using PHP code. Can anyone please help?
Below code i am trying to get the date which needs to be blocked:
$booking_closed_from = date('Y-m-d');
$booking_closed_till = date('Y-m-d', strtotime('+1 day'));
Now I am passing this $booking_closed_till date to the date-picker to disable it.
But I am not sure how to enable the date after 24hours has passed. Can anyone please help?
My Answer:
You can achieve this by using JavaScript along with PHP. Here's an example code snippet that demonstrates how you can disable the date and time slots in the date-picker based on the current timestamp:
html
Date Picker Example
Date:
In this code snippet, we are using jQuery UI datepicker to create a date-picker input field. We are setting the `minDate` option to the date that needs to be disabled (24 hours from the current timestamp). We are also using the `beforeShowDay` function to disable the specific date in the date-picker.
You can modify this code according to your requirements and integrate it with your PHP code to achieve the desired functionality.
Rate this post
3 of 5 based on 4380 votesComments