DHTMLX Booking. Start and end dates example
Live example
A schedule usually covers a period, not an endless calendar. start sets the first date the widget shows slots for and end sets the last one. This demo runs from December 1, 2025 to June 1, 2026.
const widget = new booking.Booking("#root", {
data: dataset,
start: new Date(2025, 11, 01),
end:new Date(2026, 5, 1, 23, 59, 59)
});
widget.setConfirmHandler(function(event){
const { confirm } = event;
setTimeout(() => {
Math.random() < 0.5 ? confirm.error() : confirm.done();
}, 1000);
});<!-- component container -->
<div id="root" style="height:100%"></div>
<!-- dataset -->
<script>
const dataset = [
{
id: "ee828b5d-a034-420c-889b-978840015d6a",
title: "Natalie Tyson",
category: "Therapist",
subtitle: "2 years of experience",
details: "Cleveland Clinic\n9500 Euclid Ave",
preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg",
price: "$35",
review: {
stars: 4,
count: 120,
},
slots: [
{
from: 9,
to: 20,
days: [1, 2, 3, 4, 5],
},
{
from: 10,
to: 18,
days: [6, 0],
},
],
},
{
id: "5c9b64ad-1830-4e5b-a5f9-8acea10706df",
title: "James Anderson",
category: "Allergist",
subtitle: "3 years of experience",
details: "UCLA Medical Center\n57 Westwood Plaza",
preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/11.jpg",
price: "$30",
review: {
stars: 4,
count: 64,
},
slotSize: 45,
slotGap: 10,
slots: [
{
from: "9:15",
to: 17,
days: [1, 2, 3, 4, 5],
},
],
},
// ... 44 more items (see Live Editor for full data)
];
function getDate(addDays, hoursValue = 0, minutesValue = 0) {
const date = new Date(2025, 11, 1);
const secondsValue = 0; // round to minutes
const msValue = 0;
date.setDate(date.getDate() + addDays);
date.setHours(hoursValue, minutesValue, secondsValue, msValue);
return date.getTime();
}
</script>Use case
Plenty of services sell a season rather than a rolling year. A training room is open for the length of a program. A seasonal clinic runs from autumn to spring, and a workshop takes orders for one quarter. Two dates keep the day picker inside that window, so nobody reserves a day the business does not plan to staff. The pair also publishes a schedule in stages: move end forward when the next quarter is approved.
How to do this in your app
- Set the first bookable day:
start: new Date(2025, 11, 1)opens the widget on December 1 instead of today. - Close the period:
end: new Date(2026, 5, 1, 23, 59, 59)keeps slots through the end of June 1. A slot is shown only when it finishes at or beforeend, so midnight on that day would leave it empty. - Keep the window moving: compute both dates instead of writing them in, for example
new Date()for the start and a date three months later for the end. - Optional, drop one of them: omit
startand the first day stays today. Omitendand the schedule runs for one year afterstart.
Good to know
- The defaults are today and one year ahead: without
startthe widget opens on the current date, and withoutendit shows slots for one year fromstart. - Month numbers start at zero:
new Date(2025, 11, 1)is December 1, 2025, andnew Date(2026, 5, 1)is June 1, 2026, which is standard JavaScriptDatebehavior and a common source of off by one months. - The time of day is part of the limit:
new Date(2026, 5, 1)is midnight, and this demo sets 23:59:59 so the last day still has slots. - A hardcoded range ages: the period in this demo has already passed, which is what happens to any static pair of dates in a running app.
FAQ
How do you limit a booking calendar to a date range?
Pass start and end to the constructor as Date objects. The widget then shows slots only inside that period, and the day picker follows the same limits.
What period does Booking show by default?
Slots start on the current date and run for one year. Both ends are optional, so setting end alone keeps today as the first bookable day.
Can a visitor pick a date after the end date?
No. end is the last date the widget shows available slots for, so anything later is simply not on the schedule.
API reference
- start: The first date with available slots
- end: The last date with available slots
- data: Cards and the slot rules the range is applied to
Related examples
- Initialization: the base setup with cards, slots, and a confirm handler
- Slot duration and gap: control the length of a slot and the break after it
- Filtered data loading: fetch only the slots the visitor asked for