Solution 1 :

you can set it as value

var selectElement = $('#date-time');
var date = '2020-03-19'; // default date

selectElement.on('change', (event) => {
    date = selectElement.val().split('T')[0];
    selectElement.attr('value', date+'T22:00"');
});

Problem :

I have a datetime-local input (and jQuery) and I’m trying to figure out how I can essentially autofill the time of the input. The value is not required so I can’t just set a default datetime, but I need the time to default to a predetermined time (let’s say 10:00 PM) if a user picks a date. (Other times are valid but extremely rare)

I tried to pull the incomplete value, but that appears to be impossible due to W3C’s sanitation of the value (per this SO thread and testing)

Is this even possible or will I need to abandon datetime-local?

Comments

Comment posted by custom date picker

Then you’ll need to use a

Comment posted by RobG

This doesn’t answer the OP’s question. They want to complete the date if it’s only partially keyed in, in which case

By