How to create a datetime input box in an HTML page

DateTime Input Box

In HTML, DateTime input box (DateTime pciker) is used for selecting date and time.

It helps users pick date and time without typing anything.

How to Create a DateTime Input Box

Create an HTML <input> element.

Add type="datetime-local" (type attribute with value 'datetime-local') to the <input> element. Type attribute value is set to 'datetime-local' to define the input element as a DateTime input box.

Add name="myDateTime" (name attribute with value 'myDateTime') to define the name of the <input> element.

A label <label>Pick Date Time:</label> has been added before the input element.

Have a look at the following example:

Example of DateTime Input Box


Output of the above code example

Example of DateTime Input Box in a Webpage


Pick a date and time from the above DateTime input box.


How to Create a Date Input Box

Create an HTML <input> element.

Add type="date" (type attribute with value 'date') to the <input> element. Type attribute value is set to 'date' to define the input element as a Date input box.

Add name="myDate" (name attribute with value 'myDate') to define the name of the <input> element.

A label <label>Pick Date:</label> has been added before the input element.

Have a look at the following example:

Example of Date Input Box


Output of the above code example

Example of Date Input Box in a Webpage


Pick a date from the above Date input box.

Live Code Playground

In the following HTML code editor, you can practice the above code by adding more datetime input boxes. Click on the 'Run Code' button to render the code; the rendered page will be displayed in the following HTML Code Output frame. Practice until you become comfortable and proficient with your code.

HTML logo HTML Online Editor
HTML Code Output