0

I have used following code snippet to restrict previous dates in datetimelocal input. It works fine but it returns seconds and milliseconds too. How to get only hours and minutes?

$(document).ready(function(){
    let elem = document.getElementById("application_start_date")
    const iso = new Date().toISOString();
    const minDate = iso.substring(0, iso.length - 1);
    elem.value = minDate
    elem.min = minDate
});

1 Answers1

0

Just replace the substring parameters like this

If you want date and hous+minutes,

const mn = iso.substring(0,iso.length -5) //2022-02-17T05:34:06

If you want time only then,

const mn = iso.substring(11,iso.length -5) //05:34:06