×

HTML Date

The input element in HTML has several attributes. One of its attributes is the type attribute which creates a calendar in an order that a user can select a date from the calendar. The calendar is visible only by clicking on the input field. It contains the values of the day, month, and year.

Syntax:

<input type="date">

Examples of HTML Date:

Example 1:

<!DOCTYPE html>
<html>
 
<head>
    <title> Example 1 of HTML Date </title>
    <style>
        h2 {
            color: rgb(163, 16, 248);
        }
        h3 {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        } 
        body {
            text-align: left;
        }
    </style>
</head>
 
<body bgcolor="lightyellow">
    <h2> Example 1 of HTML Date </h2>
    <h3> Enter Date <input type="date"></h3>
</body>
 
</html>

Output:

The output shows the date. When you try to input a date, a calendar appears on the screen. Now, you can choose the date from the calendar.

HTML Date

Example 2:

It is another example of an HTML date. We are using input text and input date.

<!DOCTYPE html>   
<html>  
<head>   
<title> Example 2 of HTML Date </title>  
</head>  


<body bgcolor="yellow">   


<form>   
Student Name: <input type="text" placeholder="Enter Your name" required>  
<br>  
<br>  
<label for="admission date"> Date of Admission: </label>
<input type = "date" required>   
<button type="submit" name="btn"> Submit </button>  
</form>  


</body> 


</html>

Output:

The output shows the input text, input date, and submit button. You can fill the details and submit the data. The yellow background color has also been used to make the web page look better.

HTML Date

Example 3:

We are setting the min value and the max value by using min and max attribute inside the input element.

<!DOCTYPE html>
<html>
    <head>
          <title> Example 3 of HTML Date </title>
    </head>
<body bgcolor="DarkSalmon">


Enter a date between 1990-01-01 and 2023-01-01:
<input type="date" id="Date" name="bday" min="1990-01-01" max="2023-01-01">


<p> Click the button to display the value of the min attribute. </p>


<button onclick="myFunction()"> Min Value </button>


<p> Click the button to display the value of the max attribute. </p>


<button onclick="myFunc()"> Max Value </button>


<p id="demo"></p>


<script>
function myFunction() {
  var x = document.getElementById("Date").min;
  document.getElementById("demo").innerHTML = x;
}
function myFunc() {
  var x = document.getElementById("Date").max;
  document.getElementById("demo").innerHTML = x;
}
</script>


</body>
</html>

Output:

You can see that the min and max values are fixed, and you can select the date between these values.

HTML Date

When you click the min value button, the min value will appear as shown below:

HTML Date

When you click on the max value button, the max value will appear as shown below:

HTML Date

Example 4:

Using JavaScript, we will display the current date, time, and day in this example.

<html>
<head>
  <title> Display Current Date in Html using Javascript </title>
</head>
<body bgcolor="AntiqueWhite">
  <h2> Current Date: </h2>


  <h3 id="DateTime"></h3>
</body>
  <script type="text/javascript">
  var today = new Date();
  var day = today.getDay();
  var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
  var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
  var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  var dateTime = ' Date: ' +date+' <br> Time: '+time;
  
  document.getElementById("DateTime").innerHTML = dateTime + ' <br> Day : ' + daylist[day];


  </script>
</html>

Output:

The output shows the current date, time, and day.

HTML Date

Example 5:

This example will display today’s date, day, and time on the web page.

<!DOCTYPE html>
<html>
    <head>
        <title> Example 5 of HTML Date </title>
    </head>
<body bgcolor="cyan">
<h2> Example 5 of HTML Date </h2>
<p id="date"></p>
<script>
var dates = new Date();
document.getElementById("date").innerHTML = dates;
</script>
</body>
</html>

Output:

The output shows today’s date, day, and time.

HTML Date

Example 6:

In this example, we will use the <select> and <option> tags and create options to select the date.

<!DOCTYPE html>
<html>
  <head>
    <title> Example 6 of HTML Date </title>
  </head>
<body bgcolor="lightpink">


<form action="#">
<label for="name"> Your name </label>
<input type="text" name="Your name" placeholder="Your name"> <br> <br>
<label for="address"> Your address </label>
<input type="text" name="Your address" placeholder="Your address"> 
<br> <br>
<label for="birthday"> Your Date of Birth </label>
<select name="month" id="month">
  <option value="month">Month</option>
  <option value="January">January</option>
  <option value="February">February</option>
  <option value="March">March</option>
  <option value="April">April</option>
  <option value="May">May</option>
  <option value="June">June</option>
  <option value="July">July</option>
  <option value="August">August</option>
  <option value="September">September</option>
  <option value="October">October</option>
  <option value="November">November</option>
  <option value="December">December</option>
</select>


<select name="days" id="days">
  <option value="days"> Days </option>
  <option value="1"> 1 </option>
  <option value="2"> 2 </option>
  <option value="3"> 3 </option>
  <option value="4"> 4 </option>
  <option value="5"> 5 </option>
  <option value="6"> 6 </option>
</select>


<select name="years" id="years">
<option value="years"> Years </option>
<option value="2000"> 2000 </option>
<option value="2001"> 2001 </option>
<option value="2002"> 2002 </option>
<option value="2003"> 2003 </option>
<option value="2004"> 2004 </option>
<option value="2005"> 2005 </option>
</select> <br> <br>


<input type="submit" value="Submit">
</form>


</body>
</html>
</html>

Output:

You can select the month, day, and year by clicking the drop-down buttons as shown below:

HTML Date

Browser Support:

It supports the following browsers:

  1. Google Chrome
  2. Internet Explorer
  3. Mozilla Firefox
  4. Safari
  5. Opera

Related Topics

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

HTML <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

HTML Font Color

The HTML <font> tag has an attribute called color, which defines the color of the text. We use the color attribute inside the <font> tag to specify the color of...

6 minutes read.

HTML <span> tag

The span tag in HTML is used as an inline container element to mark up a specific or special chunk of a text or a section of a page. If you...

2 minutes read.

How to Create a Portfolio Gallery using HTML and CSS?

First, before starting this, the user should know some of the basics of HTML and CSS to create a portfolio gallery. To add more functionality to the website, we can also...

7 minutes read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

How to add JavaScript to HTML

JavaScript is one of the most important languages today. It is a high-level, interpreted, lightweight programming language that makes web pages more interactive. It is a language of the web....

5 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML Headings

The titles and subtitles of our webpages are known as HTML headings. Let’s not talk about webpages but giving heading to almost everything like normal paragraphs, articles or let it...

2 minutes read.

HTML Audio

HTML AUDIO: HTML5 provides a method to embed the audio file into a webpage by using HTML5. Before HTML5 audio files is used to play on the browser with the help of...

1 minute read.

How to change text color in HTML

Changing the text colour of a web page is essential because it enhances readability. There are several ways to change the colour of the text in HTML, which are as follows: Text...

7 minutes read.

HTML Charsets

In this tutorial, we are going to discuss about the charsets in the HTML. The letters, numbers, and several other symbols are shown correctly by the web browser. All of this...

2 minutes read.

HTML <video> Tag

The Video tag in HTML is used to play video on a media player on the web page. We can also insert an audio by the video tag, but audio...

6 minutes read.

HTML Tutorial

Introduction This HTML tutorial helps beginners and professionals to learn HTML easily. HTML is a widely used web technology for website development. It stands for Hyper Text Markup Language. It is mainly used to...

7 minutes read.

Font tag in HTML

HTML stands for Hypertext Mark-up Language and is used to create web pages and other information that can be later displayed in a web browser. It also consists of a...

4 minutes read.

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

HTML Video

HTML VIDEO: HTML5 has introduced the <video> tag to embed video into the webpage directly without using the plug-ins.   Syntax: <video attributes >     <source src="address" type="video/mp4">     Your browser does not support the video tag.   </video> <video width="320" height="240" controls>     <source src="mountain.mp4" type="video/mp4">     Your browser does not support the video tag.   </video> Output: ← Prev ...

1 minute read.

HTML Code

Before jumping into the topic, let’s understand a common scenario where we have a code snippet in our HTML file. By code snippet, we mean computer code, which is written...

5 minutes read.

HTML Hide Element

The HTML hide element is used to hide the element. We place the hidden attribute inside those elements which we want to hide. The hidden attribute is a Boolean attribute. The...

3 minutes read.