Input Datetime max Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Datetime

Description

The max property sets or gets the max attribute of a datetime field, which controls the maximum date and time for a datetime field.

Set the max property with the following Values

Value Description
YYYY-MM-DDThh:mm:ssTZD Sets the maximum date and/or time allowed for the datetime field.
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 08)
  • T - a required separator if time is also specified
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 55)
  • ss - seconds (e.g. 03)
  • TZD - Time Zone Designator (Z as Greenwich Mean Time)

Return Value

A String, representing the maximum date and time allowed

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

Date and time:/*from   www . ja  v  a  2  s  . com*/
<input type="datetime" id="myDatetime" min="2000-01-01T22:57Z" max="2018-02-06T22:57Z">

<button onclick="myFunction()">Test</button>

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

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

Related Tutorials