Flatpickr Default Date AND Time

13k Views Asked by At

I'm using jquery flatpickr. When I used it in the past, I was successful with setting default date. I was also successful with setting default time. Somehow, when I try to combine both they don't work. This is my code:

  let date = '8/8/20';
  let hour = '22';
  let min = '15';

  $("#date").flatpickr({
     defaultDate: new Date(date),
     defaultHour: hour,
     defaultMinute: min,
     enableTime: true,
     dateFormat: 'm/d/Y h:i K',
     minuteIncrement: 1
  });

If I comment:

defaultDate: new Date(date)

the time is correctly defaulted.

If I comment:

defaultHour: hour,
defaultMinute: min,

the date is correctly defaulted.

But when I use both together it only defaults the time and not the date.

I would appreciate if someone can look into this. Thank You

1

There are 1 best solutions below

0
On BEST ANSWER

I found a solution. Defaulting date to YYYY-MM-DD HH:MM format worked for me.

Like this:

$("#date").flatpickr({
  enableTime: true,
  minuteIncrement: 1,
  inline: true,
  defaultDate: "2020-11-26 14:30" 
});