I originally had this working by having something like
var x = endDay - startDay;
for(//iterate for x)
{
if(startMonth = endMonth){
//Push items to array
}
}
Then I realised if I take a date from lets say 28 December 2021 -> 4 January 2022 that doesnt work.
So i'll show my code but generally this is more of a logic issue then actual code not working..
createSpecial(startDate, endDate){
var startValue = startDate.split("/");
var startDay = startValue[0];
var startMonth = startValue[1];
var startYear = startValue[2];
var endValue = endDate.split("/");
var endDay = endValue[0];
var endMonth = endValue[1];
var endYear = endValue[2];
var diff = parseInt(endDay) - parseInt(startDay);
let difference: Range[] = [];
var startdate: string = startDay.toString();
for (let i = 0; i <= diff; i++) {
var x = parseInt(startdate);
x++;
var s = startdate.toString();
s = s.padStart(2, '0');
startdate = x.toString();
difference.push({
day: s,
month: startMonth,
});
}
export class range{
day: string;
month: string;
}
Now i'm extremely unclear about how I can approach this, How can I get a value from the startDate and endDate to use to iterate and create the range in between for later use.
I would essentially just need to get how many days are between the start and end, I'll figure out how to iterate onto a next month afterwords
Edit: Comment pointed me to another question which answered this for me: https://stackoverflow.com/questions/4413590/javascript-get-array-of-dates-between-2-dates#:~:text=Try%20this%2C-,remember,-to%20include%20moment