Javascript Reference - HTML DOM Input Datetime max Property








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

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

Browser Support

max No No No No No

Syntax

Return the max property.

var v = datetimeObject.max 

Set the max property.

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




Property Values

Value Description
YYYY-MM-DDThh:mm:ssTZD Set the maximum 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. 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)
  • TZD - Time Zone Designator

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  ww. j  av 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").max = "2011-01-01T01: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 maximum date and time allowed for a datetime field.


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

</body>
</html>

The code above is rendered as follows: