HTML DOM Input Datetime value Property


The HTML DOM Input Datetime value property returns a string, which is the value of the value attribute of input datetime. User can also set it to a new string.

Syntax

Following is the syntax −

  • Returning string value
inputDatetimeObject.value
  • Setting value attribute to a string value
inputDatetimeObject.value = ‘String’

Example

Let us see an example of Input Datetime value property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Datetime Value</title>
</head>
<body>
<form>
<div>
Date & Time: <input type="datetime" id="datetimeSelect" value="2015-08-22T16:24Z">
</div>
</form>
<button onclick="changeValue()">Change Value</button>
<div id="divDisplay"></div>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputDatetime = document.getElementById("datetimeSelect");
   divDisplay.textContent = 'Current value: '+ inputDatetime.value;
   function changeValue(){
      var currDatetime = inputDatetime.value;
      inputDatetime.value = '2017-03-17T16:24Z';
      divDisplay.textContent = 'Updated value from: '+currDatetime+' to: '+ inputDatetime.value;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Change Value’ button −

After clicking ‘Change Value’ button −

Updated on: 30-Jul-2019

76 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements