jQuery UI Datepicker attaches a calendar to an input field so users can choose a date. You can control formatting, allowed ranges, default dates, year/month navigation and per-day availability.
<input type="text" id="date_picker" placeholder="Calendar">
$( function () {
$( "#date_picker" ).datepicker({
dateFormat: "dd-mm-yy"
});
});
Use the dateFormat option to control how the selected date appears in the input.
const dateFormats = [
"dd-mm-yy", // 15-12-2026
"d-mm-yy", // 5-12-2026
"dd-m-yy", // 05-2-2026
"dd-mm-y", // 05-02-26
"dd-M-yy", // 05-Sep-2026
"dd-MM-yy", // 05-September-2026
"'On' d 'Day of' MM ', Year:' yy"
];
d / dd: day of month.D / DD: short/full weekday name.m / mm: month number.M / MM: short/full month name.y / yy: two-digit/four-digit year.Demo: Datepicker date formats →
Date:
<input type="text" id="date_picker1">
<div id="date_selected"></div>
$( function () {
$( "#date_picker1" ).datepicker({
dateFormat: "dd-mm-yy"
});
$( "#date_picker1" ).on( "change", function () {
const selectedDate = $( this ).val();
$( "#date_selected" ).text( selectedDate );
});
});
Demo: change event with Datepicker →
firstDay accepts 0 to 6. The default is 0 for Sunday; 1 starts with Monday and 6 starts with Saturday.
$( "#date_picker" ).datepicker({
firstDay: 1
});
Demo: change the first day of the week →
Use relative values or Date objects to prevent selection outside an allowed range.
$( "#date_picker" ).datepicker({
dateFormat: "mm-dd-yy",
maxDate: 0
});
$( "#date_picker" ).datepicker({
dateFormat: "dd-mm-yy",
minDate: "-1w",
maxDate: "+1w"
});
Demo: minimum and maximum dates →
defaultDate controls the date initially shown when the input has no value. Use setDate when you want to set the widget's selected date and input value.
<input type="text"
id="date_picker"
class="form-control"
value="14-05-2026">
$( "#date_picker1" ).datepicker({
dateFormat: "dd-mm-yy",
defaultDate: "14-05-2026"
});
const selectedDate = new Date( 2026, 4, 14 );
$( "#date_picker2" ).datepicker( "setDate", selectedDate );
Demo: defaultDate and setDate →
$( "#date_picker1" ).datepicker({
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true,
yearRange: "c-15:c+5"
});
You can also use a fixed range such as "1990:2035".
Demo: year selection with a range →
When a start date is selected, use it as the minimum allowed end date. When an end date is selected, use it as the maximum allowed start date.
$( function () {
const $start = $( "#start_date" );
const $end = $( "#end_date" );
$start.datepicker({
dateFormat: "dd-mm-yy",
onSelect: function () {
$end.datepicker(
"option",
"minDate",
$start.datepicker( "getDate" )
);
}
});
$end.datepicker({
dateFormat: "dd-mm-yy",
onSelect: function () {
$start.datepicker(
"option",
"maxDate",
$end.datepicker( "getDate" )
);
}
});
});
Demo: linked start and end dates →
The same minDate/maxDate pattern can enforce a maximum event duration, such as two weeks.
function addDays( date, days ) {
const result = new Date( date );
result.setDate( result.getDate() + days );
return result;
}
// After choosing the start date:
const start = $( "#start_date" ).datepicker( "getDate" );
$( "#end_date" ).datepicker(
"option",
{
minDate: start,
maxDate: addDays( start, 14 )
}
);
Demo: fixed range using separate start/end calendars →
Demo: fixed range using a single calendar →
beforeShowDay runs for each date before its cell is displayed. Return an array with three values:
[
true, // selectable?
"special-date", // CSS class
"Available date" // tooltip text
]
A callback can decide availability:
function checkDate( selectedDate ) {
const day = selectedDate.getDay();
const isWeekend = day === 0 || day === 6;
return [
!isWeekend,
isWeekend ? "unavailable-date" : "",
isWeekend ? "Not available" : "Available"
];
}
$( "#date_picker" ).datepicker({
dateFormat: "dd-mm-yy",
beforeShowDay: checkDate
});
Demo: disable selected day numbers →
For weekend logic, see the JavaScript getDay() tutorial.
Demo: disable fixed dates across different months →
Database-backed availability can populate the unavailable-date list before initializing Datepicker. The event calendar tutorial shows the broader PHP/MySQL application pattern.
$.datepicker._clearDate(). The leading underscore indicates an internal/private method. Prefer the public widget API.
$( "#date_picker" ).datepicker( "setDate", null );
$( "#reset" ).on( "click", function () {
$( "#date_picker1" )
.datepicker( "option", {
minDate: null,
maxDate: null
})
.datepicker( "setDate", null );
$( "#msg" ).text( "" );
});
.ui-datepicker {
width: 24em;
}
Use a <div> instead of an input to create an inline Datepicker that stays visible.
<div id="date_picker_inline"></div>
Demo: date plus hour, minute and second sliders →
Parse the exact format you expect instead of letting PHP guess the input format.
<?php
$input = $_POST['date_enq'] ?? '';
$date = DateTime::createFromFormat('d-m-Y', $input);
if ($date && $date->format('d-m-Y') === $input) {
$dateEnquiry = $date->format('Y-m-d');
} else {
$dateEnquiry = date('Y-m-d');
}
?>

jQuery UI themes change the visual style without changing the Datepicker API.
Demo: Datepicker with selectable themes →
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| jagan | 04-03-2016 |
| hi, can u help me to develop project with the requirement of mine, in jquery 2nd,4th saturday and all sunday's should be disable using datepicker in asp.net. pls help me | |
| rickchow | 08-07-2016 |
| Jquery date picket looks nice. Where is the source code? Full code that I can run on my page? | |
| Akila | 09-09-2017 |
| how to call the script in text box input type | |
| smo1234 | 27-09-2017 |
| This is explained at the top of the tutorial. Note that this date piker will work with all JQuery support. | |