Javascript Reference - HTML DOM Input Datetime min Property








The min attribute from input datetime element specifies the minimum value for a datetime field.

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

Browser Support

min No No No No No

Syntax

Return the min property.

var v = datetimeObject.min

Set the min property.

datetimeObject.min=YYYY-MM-DDThh:mm:ssTZD




Property Values

Value Description
YYYY-MM-DDThh:mm:ssTZD Set the minimum date and time for the datetime field.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 01)
  • T - a required separator for time field
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 51)
  • ss - seconds (e.g. 01)
  • TZD - Time Zone Designator

Return Value

A String type value representing the minimum date and time allowed.

Example

The following code shows how to change the minimum date and time.


<!DOCTYPE html>
<html>
<body>
<!--from  w  w w.ja v a2 s.  c  o m-->
Date and time:
<input type="datetime" id="myDatetime" min="2000-01-01T22:57Z" max="2014-02-06T22:57Z">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myDatetime").min = "2009-02-01T21:57Z";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the minimum date and time for a datetime field.


<!DOCTYPE html>
<html>
<body>
Enter a date and time between 2000-01-01 10:27 PM and 2014-04-06 10:57 PM:
<input type="datetime" id="myDatetime" min="2000-01-01T22:27Z" max="2014-04-06T22:57Z">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w  w w .ja v a 2s.co  m-->
    var x = document.getElementById("myDatetime").min;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: