Jquery date picker disable dates before today
- By Preneesh AV --
- 18-Mar-2018 --
- 31 Comments
This post explains how to disable all dates before current date in Jquery datepicker. In below code the id of the activeform input field is assigned with datepicker.
The function NotBeforeToday handles the disabling of date selection before current date.
$( '#campaigns-campaignenddate').datepicker({ dateFormat: "dd-mm-yy" ,beforeShowDay: NotBeforeToday}).val();
function NotBeforeToday(date)
{
var now = new Date();
//this gets the current date and time
if (date.getFullYear() == now.getFullYear() && date.getMonth() == now.getMonth() && date.getDate() > now.getDate())
return [true];
if (date.getFullYear() >= now.getFullYear() && date.getMonth() > now.getMonth())
return [true];
if (date.getFullYear() > now.getFullYear())
return [true];
return [false];
}
