Search code examples
phpjquerydatetimepickertimepicker

Set dropdown with AM/PM options for time picker in PHP JQuery


I got a jquery plugin for a datetimepicker to be called in my PHP file. Everything works well, even until it getting integrated or posted into the database. However, I would like it to be in an AM/PM option, with the hours value starting at 1 and ending at 12. I have found a solution in a previous question here in the site, but what it only does is to convert the selected value (in 24-hour setting) into the equivalent time in AM/PM format. What I would prefer is that the dropdown of hours:minutes would be in hours:minutes AM/PM display, in a 12-hour setting.

The documentation for the jquery is at https://github.com/xdan/datetimepicker/blob/master/doc.tpl and a sample image of the time picker is at https://raw.githubusercontent.com/xdan/datetimepicker/master/screen/3.png. I have changed some values in the js files, such as loops reaching to 24 (assuming these are creating the values for hours 00-23) and made them 13 but to no effect. Thanks!


Solution

  • Instead of using format, try using formatTime when initialising the datetime picker. The following should generate times in the 12h am/pm format in the drop-down,

    jQuery('#datetimepicker').datetimepicker({
        datepicker: false,
        formatTime: 'h:i a'
    });