How to disable previous dates in the date picker using JQuery
File name :
<html>
<head>
<title>How to disable previous dates in date picker using JQuery - ittutorial.in</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
<body>
<h1>How to disable previous dates in date picker using JQuery</h1>
Date : <input id="date_picker" type="date">
<script language="javascript">
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
});
</script>
<script>
function ageCalculate() {
var user_input = document.getElementById("dob").value;
var userinput = user_input.split("-").reverse().join("-");
//var userinput = "1984-01-01";
var dob = new Date(userinput);
var yyyy = dob.getFullYear();
if(userinput==null || userinput=='') {
document.getElementById("lblError").innerHTML = "Please Select Date of Birth!";
return false;
} else {
// var todate = new Date();
//var todate = new Date('2023/05/12');
var todate = new Date('2023-05-12');
// calculate month difference from current date in time
// var month_diff = Date.now() - dob.getTime();
var month_diff = todate - dob.getTime();
//convert the calculated difference in date format
var age_dt = new Date(month_diff);
// var month = d.getUTCMonth() + 1; // Since getUTCMonth() returns month from 0-11 not 1-12
var month = age_dt.getUTCMonth();
var day = age_dt.getUTCDate(); // +1 means current date included
//extract year from date
var year = age_dt.getUTCFullYear();
//now calculate the age of the user
var age = Math.abs(year - 1970);
lblError.innerHTML = "Date Of Birth is Not Eligible.";