Getting Started
The simplest way to attach a date picker to any text input with a single line of initialization.
Simple Date Picker
Attach to any text input. Opens via icon click or input click. Supports full keyboard navigation inside the calendar, and manual entry in DD/MM/YYYY format which auto-converts to the configured output format.
new DatePicker(element, {
format: 'DD MMM YYYY',
minYear: '-99y',
maxYear: '+10y',
closeOnSelect: true
});
Default Value
Pre-populate the picker with any Date object using picker.setValue(date). Useful for edit forms where a date is already stored. Use picker.getValue() to read the current selection back.
const picker = new DatePicker(element, {
format: 'DD MMMM YYYY'
});
// Set value programmatically
picker.setValue(new Date());
// Read value back
const date = picker.getValue();
Date Formats
13 output formats out of the box. Select a date in any picker below to see it rendered in that format.
DD MMM YYYY
Short month name → 09 Dec 2025
format: 'DD MMM YYYY'
DD MMMM YYYY
Full month name → 09 December 2025
format: 'DD MMMM YYYY'
YYYY-MM-DD
ISO 8601 → 2025-12-09
format: 'YYYY-MM-DD'
MM/DD/YYYY
US slash format → 12/09/2025
format: 'MM/DD/YYYY'
MMMM DD, YYYY
US long format → December 09, 2025
format: 'MMMM DD, YYYY'
D/M/YYYY
No zero-padding → 9/12/2025
format: 'D/M/YYYY'
Date Range Picker
Link two pickers via onChange callbacks so selecting a start date automatically limits the end, and vice versa.
Hotel Booking — Check-in & Check-out
Select a Check-in date first — the Check-out picker will automatically restrict to only allow dates after it. Selecting a Check-out date will also cap the Check-in accordingly. The number of nights is calculated live.
const checkIn = new DatePicker(startEl, {
format: 'DD MMM YYYY',
onChange: (date) => {
checkOut.options.minDate = date || null;
}
});
const checkOut = new DatePicker(endEl, {
format: 'DD MMM YYYY',
onChange: (date) => {
checkIn.options.maxDate = date || null;
}
});
Date Constraints
Restrict selectable dates using minDate and maxDate. Disabled dates appear greyed-out and cannot be clicked.
Past Dates Only
Set maxDate: new Date() to make today the last selectable date. Ideal for date-of-birth fields, historical records, or logging past events.
new DatePicker(element, {
format: 'DD/MM/YYYY',
maxDate: new Date()
});
Future Dates Only
Set minDate: new Date() to make today the earliest selectable date. Perfect for booking forms, delivery scheduling, appointment picking, or event sign-ups.
new DatePicker(element, {
format: 'DD/MM/YYYY',
minDate: new Date()
});
Custom Date Window
Combine minDate and maxDate to lock selection to a specific window. Useful for fiscal year pickers, project timelines, or conference scheduling.
new DatePicker(element, {
format: 'DD MMM YYYY',
minDate: new Date(2026, 0, 1),
maxDate: new Date(2026, 11, 31)
});
Year Range Limit
Use minYear / maxYear to restrict the year picker grid. Accepts absolute years (2020) or relative offsets ('-5y', '+10y'). Click the year in the header to see the year grid.
new DatePicker(element, {
format: 'DD/MM/YYYY',
minYear: 2020,
maxYear: 2030
// or relative: '+10y', '-5y'
});
Configuration Options
Customize week start day, react to selections with callbacks, and control calendar behavior.
Week Start Day
By default the week starts on Sunday. Set firstDay: 1 for a Monday start (ISO 8601 standard). Open both calendars side-by-side and compare the column order.
firstDay: 0firstDay: 1// Default — week starts Sunday
new DatePicker(element, { firstDay: 0 });
// ISO 8601 — week starts Monday
new DatePicker(element, { firstDay: 1 });
onChange Callback
The onChange(date) fires every time a date is selected or cleared. Use it to sync with a form state, update related UI, trigger validation, or display the same date in multiple formats at once.
new DatePicker(element, {
format: 'DD MMM YYYY',
onChange: (date) => {
if (date) {
console.log('Selected:', date);
console.log('ISO:', date.toISOString());
} else {
console.log('Cleared');
}
}
});
Smart Positioning
The calendar detects available viewport space and auto-positions itself. You can override it with 7 orientation options.
Auto (Default)
Automatically selects below or above based on available space. Scrolls and resizes are tracked in real time so the calendar stays in the right place even in complex layouts.
orientation: 'auto' // default
Fixed: bottom-right
Force the calendar to always open below the input, aligned to the right edge. Useful in right-aligned layouts where the default left-aligned dropdown would overflow.
orientation: 'bottom-right'