I'm struggling to subtract one day from the variable endDate
, which is currently a string.
I attempted the following method:
moment(this.endDate).subtract(1, 'day').format()
Unfortunately, this approach did not yield the desired results.
public ngOnChanges(): void {
const startDate = this.startDate ? moment(this.startDate).format() : moment().startOf('day').format();
const endDate = this.endDate ? moment(this.endDate).format() : moment(startDate).endOf('day').format();
this.datePicker = new DatePicker(startDate, endDate);
this.setDatePicker();
if (this.continiousDatesValue !== null) {
this.continiousDatesValueMoment = moment(this.continiousDatesValue);
}
if (this.previousDatesValue !== null) {
this.previousDatesValueMoment = moment(this.previousDatesValue);
}
}
Additionally, I need to perform a similar subtraction operation on the "endDate" string in the following function:
private onDatesChange(): void {
this.startDateChange.emit(this.datePicker.startDate);
this.endDateChange.emit(this.datePicker.endDate);
this.startEndDateChange.emit({startDate: this.datePicker.startDate, endDate: this.datePicker.endDate});
this.isOpen = false;
}