Example:
PHP-Code:
<input id="datetime-picker" type="text">
<script>
// Array with disabled times and days
const disabledTimes = [
{ day: "2024-12-25", times: ["10:00", "14:00"] }, // Christmas: closed between 10:00 and 14:00
{ day: "2024-12-31", times: ["18:00", "22:00"] } // New Year's Eve: closed between 6:00 p.m. and 10:00 p.m.
];
function isTimeDisabled(date) {
const formattedDate = date.toISOString().split("T")[0];
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
const time = `${hours}:${minutes}`;
return disabledTimes.some(disabled =>
disabled.day === formattedDate && disabled.times.includes(time)
);
}
flatpickr("#datetime-picker", {
enableTime: true,
dateFormat: "Y-m-d H:i",
minuteIncrement: 30,
disable: [
function(date) {
return isTimeDisabled(date);
}
]
});
</script>
Einen Kommentar schreiben: