Javascript Reference - HTML DOM Input DatetimeLocal max Property








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

The max attribute specifies the maximum value for a local datetime field.

Browser Support

max Yes No No Yes Yes

Syntax

Return the max property.

var v = datetimelocalObject.max 

Set the max property.

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




Property Values

Value Description
YYYY-MM-DDThh:mm:ss.ms Set the maximum 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 maximum date and time allowed.

Example

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


<!DOCTYPE html>
<html>
<body>
<!--   w w w .  ja v a2 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").max = "2012-01-01T22:22:55";
    document.getElementById("demo").innerHTML = "";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

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


<!DOCTYPE html>
<html>
<body>
<!-- ww w.jav  a 2 s. co  m-->
Enter a date and time between 2000-10-06 12:22:55 and 2014-10-16 12:25:33:
<input type="datetime-local" id="myLocalDate" min="2000-10-06T12:22:55" max="2014-10-16T12:25:33">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").max;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: