The Input Date value property is used for setting or returning the value of the value attribute of a date field.
The Input Date value attribute can be used for specifying a date for the date field.
Syntax:
- For returning the value property:
inputdateObject.value
- For setting the value property:
inputdateObject.value = YYYY-MM-DD
Property Value:
- YYYY-MM-DD :It is used to specify the date.
- YYYY: It specifies the year.
- MM: It specifies the month.
- DD: It specifies the day of the month.
Return Value: It returns a string value which specify the value of date for the date field.
Below program illustrates the Date value property :
Example 1: Setting a date for a datetime field.
html
<!DOCTYPE html>
<html>
<head>
<title>Input Date value Property in HTML</title>
<style>
h1 {
color: green;
}
h2 {
font-family: Impact;
}
body {
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>Input Date value Property</h2>
<br> Date Of Birth:
<input type="date" id="Test_Date">
<p>To set a date for the date field,
double-click the "Set Date" button.</p>
<button ondblclick="My_Date()">Set Date</button>
<p id="test"></p>
<script>
function My_Date() {
document.getElementById("Test_Date").value = "2019-02-04";
}
</script>
</body>
|
Output:

After clicking the button

Example-2: Below code returns a date value property.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Input Date value Property in HTML</title>
<style>
h1 {
color: green;
}
h2 {
font-family: Impact;
}
body {
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>Input Date value Property</h2>
<br> Date Of Birth:
<input type="date" id="Test_Date" value="2013-12-12">
<p>To return a date for the date field,
double-click the "Set Date" button.</p>
<button ondblclick="My_Date()">Return Date</button>
<p id="test"></p>
<script>
function My_Date() {
var g = document.getElementById("Test_Date").value;
document.getElementById('test').innerHTML= g;
}
</script>
</body>
|
Before:

After:

Supported Web Browsers:
- Apple Safari 14.1
- Edge 12
- Firefox 57
- Google Chrome 20
- Opera 11
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Nov, 2022
Like Article
Save Article