I have a unique problem. I am allowing users to set the start of the week as any day. For the code it can be text as "Tuesday" or a number from 0-6. I want to get 2 unix timestamps of the last full week from their chosen start date. So it's Monday now. If they chose Thursday as their start week I want a value of 12am 10 days ago and another for 3 days ago.
So i have this
//Day club week starts on
let startday = new Date(res.data.payload[0].startday * 1000).getDay()
let todaysDay = new Date().getDay()
let dayOffset = todaysDay - startday
if (startday > todaysDay) {
dayOffset = todaysDay + (7 - startday)
}
var endWeek = new Date()
endWeek.setDate(endWeek.getDate() - dayOffset)
var startWeek = new Date()
endWeek.setDate(endWeek.getDate() - (dayOffset + 7))
But I don't know how to create a new date X days ago at 12am.
Is this on the right track? Thanks