Javascript DOM HTML Input Datetime min Property get

Introduction

Get the minimum date and time allowed for a datetime field:

var x = document.getElementById("myDatetime").min;

Click the button to display the value of the min attribute of the datetime field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Enter a date and time between 2000-01-01 10:57 PM and 2014-02-06 10:57 PM:
<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() {//from w w w  .j av a  2  s .  com
  var x = document.getElementById("myDatetime").min;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

The min attribute sets the minimum value of date and time for a datetime field.

The min property accepts and returns a String type value.

Property Values

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



PreviousNext

Related