1

I need to select date from datetime-local, but I want the minutes to be preselected as '00'

Like: mm/dd/yyyy --:--:00

So that if the user selects a date-time, minutes will always be set to 00.

My HTML code is: <input type="datetime-local" name="datetime_regular_start" id="datetime_regular_start" value="" required>

I have tried

const dateControl = document.querySelector('input[type="datetime-local"]');
dateControl.value = "2020-06-01T08:30";

And the the whole date-time value is preselected,

So I have tried changing only the minutes to 00.

const dateControl = document.querySelector('input[type="datetime-local"]');
dateControl.value = "yyyy-mm-dd-HH:00";

But Its not working. How should I set the value of minutes to always 00?

1 Answer 1

2

You can set the step attribute to 3600 seconds (i.e. one hour):

<input type="datetime-local" step="3600">

Browser support might vary. It works in the current version of Chrome, but not in Firefox.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.