Input Datetime value attribute

Definition and Usage

value Attribute settings or returns the value of the value attribute of the date-time field.

HTML value attribute specifies the date and time for the date-time field.

See Also:

HTML Reference Manual:HTML <input> value Attribute

Instance

Example 1

Set the date and time for the date-time field:

document.getElementById("myDatetime").value = "2014-01-02T11:42Z";

Try It Yourself

Example 2

Get the date and time of the date-time field:

var x = document.getElementById("myDatetime").value;

Try It Yourself

Syntax

Return the value attribute:

datetimeObject.value

Set the value attribute:

datetimeObject.value = YYYY-MM-DDThh:mm:ssTZD

Attribute Value

Value Description
YYYY-MM-DDThh:mm:ssTZD

Specify the date and/or time.

Component Description:

  • YYYY - Year (e.g., 2023)
  • MM - Month (e.g., 02 represents February)
  • DD - Day of the month (e.g., 15)
  • T - If a time is specified, this is a required separator
  • hh - Hours (e.g., 22 represents 10 PM)
  • mm - Minutes (e.g., 55)
  • ss - Seconds (e.g., 06)
  • TZD - Time Zone Indicator (Z represents Zulu, also known as Greenwich Mean Time)

Technical Details

Return Value: A string value representing the date and time of the date-time field.

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support

Note:The <input type="datetime"> element does not display any date-time field/calendar in any mainstream browser except Safari.