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 −

stringValue Details
date It defines that input type is date
datetime It defines that input type is datetime
checkbox It defines that input type is checkbox
text It 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: 2019-07-30T22:30:26+05:30

414 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements