Disable previous and past Year Dates in Input Type Date (TextMode Date) in jQuery

Last Reply 16 days ago By arunkurmi

Posted 16 days ago

Im using this example Disable previous Dates in Input Type Date (TextMode Date) using jQuery in ASP.Net

I want to know how to disable dates before and after the current year so there is no need to update interfaces.

Posted 16 days ago

Hi YulIhnio,

Check this sample.

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var currentYear = new Date().getFullYear();
            var minDate = currentYear + '-01-01';
            var maxDate = currentYear + '-12-31';
            $('#txtDate').attr('min', minDate);
            $('#txtDate').attr('max', maxDate)
        });
    </script>
    <input type="date" id="txtDate" />
</body>
</html>

Demo