Javascript DOM HTML Input DatetimeLocal min Property get

Introduction

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

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

Enter a date and time between 2000-10-06 22:22:55 and 2014-11-16 21:25:33:
<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() {/*  w  ww.  j  av a 2s . c o m*/
  var x = document.getElementById("myLocalDate").min;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

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

Date format:

Value Description
YYYY-MM-DDThh:mm:ss.ms Specifies the minimum date and time allowed for the local datetime field.

Components of value:

  • 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 also specified
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 55)
  • ss - seconds (e.g. 03)
  • ms - milliseconds (e.g. 510)

The min property returns a String representing the minimum date and time allowed.




PreviousNext

Related