Вывести все даты между периодами js

Всех приветствую. У меня есть два поля input с периодами. Так же мне нужно записать все даты в массив = в период с (date_start = 01.08.2022, date_end = 15.08.2022)

И получить подобный резульатат arr = ['02.08','03.08']


Ответы (1 шт):

Автор решения: Enokin

Можно вот так, только приведите начальных даты в нужный формат

function getDatesInRange(startDate, endDate) {
  const date = new Date(startDate.getTime());

  date.setDate(date.getDate() + 1);

  const dates = [];

  while (date < endDate) {
    dates.push(new Date(date));
    date.setDate(date.getDate() + 1);
  }

  return dates;
}

const d1 = new Date('2022-08-01');
const d2 = new Date('2022-08-15');

console.log(getDatesInRange(d1, d2));

→ Ссылка