Hello this a result i could've achieve that could help you. i've used a js script to make this. please let me know if it works well for you
class WeekGenerator {
constructor() {
this.currentWeek = [];
this.SelectedDateList = [];
this.selectedYear = new Date().getFullYear();
this.selectedMonth = new Date().getMonth();
this.selectedDay = new Date().getDate();
this.weekDays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
this.monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
}
generateCurrentWeek(day, month, year) {
const selectedDate = new Date(year, month, day);
const startOfWeek = new Date(selectedDate);
startOfWeek.setDate(selectedDate.getDate() - selectedDate.getDay());
this.currentWeek = [];
this.SelectedDateList = [];
for (let i = 0; i < 7; i++) {
const currentDate = new Date(startOfWeek);
currentDate.setDate(startOfWeek.getDate() + i);
const formattedDate = `${currentDate.getFullYear()}-${(
currentDate.getMonth() + 1
)
.toString()
.padStart(2, "0")}-${currentDate
.getDate()
.toString()
.padStart(2, "0")}`;
this.currentWeek.push({
date: currentDate.getDate(),
day: this.weekDays[currentDate.getDay()],
month: this.monthNames[currentDate.getMonth()],
year: currentDate.getFullYear(),
});
this.SelectedDateList.push({ date: formattedDate });
}
this.displayWeek();
}
previousWeek() {
this.adjustWeek(-7);
}
nextWeek() {
this.adjustWeek(7);
}
adjustWeek(offsetDays) {
const firstDayOfCurrentWeek = new Date(
this.selectedYear,
this.selectedMonth,
this.selectedDay
);
firstDayOfCurrentWeek.setDate(firstDayOfCurrentWeek.getDate() +
offsetDays);
this.selectedYear = firstDayOfCurrentWeek.getFullYear();
this.selectedMonth = firstDayOfCurrentWeek.getMonth();
this.selectedDay = firstDayOfCurrentWeek.getDate();
this.generateCurrentWeek(
this.selectedDay,
this.selectedMonth,
this.selectedYear
);
}
displayWeek() {
const weekDisplay = document.getElementById("weekDisplay");
weekDisplay.innerHTML = "";
this.currentWeek.forEach((dayInfo) => {
const li = document.createElement("li");
li.textContent = `${dayInfo.day}, ${dayInfo.date} ${dayInfo.month}
${dayInfo.year}`;
weekDisplay.appendChild(li);
});
}
}
const weekGenerator = new WeekGenerator();
weekGenerator.generateCurrentWeek(
weekGenerator.selectedDay,
weekGenerator.selectedMonth,
weekGenerator.selectedYear
);
document
.getElementById("prevWeekBtn")
.addEventListener("click", () => weekGenerator.previousWeek());
document
.getElementById("nextWeekBtn")
.addEventListener("click", () => weekGenerator.nextWeek());