Javascript Reference - HTML DOM Input DatetimeLocal min Property








The min attribute specifies the minimum value for a local datetime field.

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

Browser Support

min Yes No No Yes Yes

Syntax

Return the min property.

var v = datetimelocalObject.min

Set the min property.

datetimelocalObject.min=YYYY-MM-DDThh:mm:ss.ms




Property Values

Value Description
YYYY-MM-DDThh:mm:ss.ms Set the minimum date and time for the local datetime field.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 09)
  • 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)
  • ms - milliseconds (e.g. 511)

Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
Enter a date and time between 2000-10-06 12:12:55 and 2014-11-16 21:25:33:
<input type="datetime-local" id="myLocalDate" min="2000-10-06T12:12:55" max="2014-11-16T21:25:33">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from  ww  w .j a v  a2 s. c o m-->
<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").min;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

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


<!DOCTYPE html>
<html>
<body>
<!--  www  . j a  v a 2  s.  c  o  m-->
Date and time:
<input type="datetime-local" id="myLocalDate" min="2000-10-06T22:22:55" max="2014-11-16T21:25:33">
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").min = "2004-05-05T16:15:23";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows: