JQuery Datepicker: The quickest way to add hour and minute values to form’s date input field

The JQuery UI library’s Datepicker function is very convenient.  Here’s a way to override the date field if you want to allow the user to also input the time of day along with it without adding an extra field and deal with merging the values in the backend.  You can also add “+d.getSeconds()” if you want to allow seconds, but I find that’s wasted space.

  $('.datepicker').datepicker({
        dateFormat: 'yy-dd-mm',
        onSelect: function(datetext){
            var d = new Date(); // current time
            datetext=datetext+" "+d.getHours()+":"+d.getMinutes();
            $('.datepicker').val(datetext);
        },
    });

 

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *