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);
        },
    });

 

Aaron Belchamber has written 247 articles

Leave a Reply

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