Javascript Reference - HTML DOM Input Date min Property








The min attribute from input date field specifies the minimum value (date) for a date field.

The min property sets or gets the value of the min attribute of a date field.

Browser Support

min Yes No No Yes Yes

Syntax

Return the min property.

var v = inputdateObject.min

Set the min property.

inputdateObject.min=YYYY-MM-DD




Property Values

Value Description
YYYY-MM-DD Set the minimum date value allowed for the date field.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 09)

Return Value

A String type value representing the minimum date allowed.

Example

The following code shows how to change the minimum date.


<!DOCTYPE html>
<html>
<body>
<!--from  w w w. j a  va 2  s.  c  o  m-->
Date:
<input type="date" id="myDate" name="bday" min="1980-01-01" max="2000-01-01">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myDate").min = "1999-01-01";
    document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to use get the minimum date allowed for a date field.


<!DOCTYPE html>
<html>
<body>
Enter a date between 1980-01-01 and 2000-01-01:
<input type="date" id="myDate" name="bday" min="1980-01-01" max="2000-01-01">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  w w  w.  ja  va 2 s . c  o  m-->
    var x = document.getElementById("myDate").min;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: