HTML DOM Input Datetime max Property


The HTML DOM Input Datetime max property returns/sets max attribute of Input Datetime.

Syntax

Following is the syntax −

  • Returning string value
inputDatetimeObject.max
  • Setting max to string value
inputDatetimeObject.max = YYYY-MM-DDThh:mm:ssTZD

String Values

Here, “YYYY-MM-DDThh:mm:ssTZD” can be the following −

stringValueDetails
YYYYIt defines year (eg:1998)
MMIt defines month (eg: 05 for May)
DDIt defines Day (eg: 24)
TIt is a separator for date and time
hhIt defines hour (eg:12)
mmIt defines minutes (eg:48)
ssIt defines seconds (eg:00)
TZDTime Zone Designator (IST denotes Indian Standard Time)

Example

Let us see an example of Input Datetime max property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Datetime Max</title>
</head>
<body>
<form>
Date & Time: <input type="datetime" id="dateTime" name="DateSelect" value="2019-12-31T23:49:59Z" max="2019-12-31T23:59:59Z">
</form>
<button onclick="getMaxDate()">Renew Insurance</button>
<div id="divDisplay"></div>
<script>
   var inputDate = document.getElementById("dateTime");
   var divDisplay = document.getElementById("divDisplay");
   divDisplay.textContent = 'Insurance Datetime: '+inputDate.max;
   function getMaxDate() {
      var oldInputDate = inputDate.max;
      inputDate.max = '2029-12-31T23:49:59Z';
      divDisplay.textContent = 'New Insurance Datetime: '+inputDate.max;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Renew Insurance’ button −

After clicking ‘Renew Insurance’ button −

Updated on: 30-Jul-2019

83 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements