I have start and end dates in my component which I am getting using moment library through the time picker.
So suppose my datepicker selects startDate and endDate for the today. Now I need another dates let's say previousStartDate and previousEndDate which should be the same time difference compared to startDate and endDate.
startDate = '20-06-2019 00:00:00'
endDate = '20-06-2019 23:59:59'
So the previousStartDate and previousEndDate should be
previousStartDate = '19-06-2019 00:00:00'
previousEndDate = '19-06-2019 23:59:59'
How can do that?
I have tried this but with no success
getPreviousStartDates ({ startDate, endDate }) {
const diff = endDate.diff(startDate)
const diffDuration = moment.duration(diff)
const subtractStartDate = startDate.subtract(diff)
console.log({subtractStartDate})
return subtractStartDate
}
Some more clarification
Suppose The time difference between the startDate and endDate is 3 days (17-6-2019 00:00:00 && 19-6-2019 23:59:59) then the time difference between previousStartDate and previousEndDate should be the same but past 3 days. (14-6-2019 00:00:00 && 16-6-2019 23:59:59)