HTML DOM Input Datetime type Property


The HTML DOM Input Datetime type property returns/sets type of Input Datetime.

Syntax

Following is the syntax −

  • Returning string value
inputDatetimeObject.type
  • Setting type to string value
inputDatetimeObject.type = stringValue

String Values

Here, “stringValue” can be the following −

stringValueDetails
dateIt defines that input type is date
datetimeIt defines that input type is datetime
checkboxIt defines that input type is checkbox
textIt defines that input type is text

Example

Let us see an example of Input Datetime type property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Datetime type</title>
</head>
<body>
<form>
<div>
Date of Birth: <input type="datetime" id="datetimeSelect" value="2000-09-17T19:22Z">
</div>
</form>
<button onclick="changeType()">Get Time and Date</button>
<div id="divDisplay"></div>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputDatetime = document.getElementById("datetimeSelect");
   divDisplay.textContent = 'Input type: '+ inputDatetime.type;
   function changeType(){
      if(inputDatetime.type === 'text'){
         var currDate = inputDatetime.value.split("T")[0];
         var currTime = inputDatetime.value.split("T")[1];
      }
      divDisplay.textContent = 'Input Date: '+ currDate+', Input Time: '+currTime;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Get Time and Date’ button −

After clicking ‘Get Time and Date’ button −

Updated on: 30-Jul-2019

305 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements