0
I would like to know how to increase the expiration date of a purchase. Example: the person made a purchase, and put the due date for the day 30 March, then the date of the second installment would be 29 April. Follow function and HTML code.
<ion-card *ngFor="let p of parcelasCobranca; let i = index">
Parcela
<ion-item>
<ion-label stacked>Valor: {{ valorParcela }}</ion-label>
</ion-item>
<ion-item>
<ion-label stacked>Data de vencimento *</ion-label>
<ion-input type="date" formControlName="due_date" name="due_date" id="due_date"></ion-input>
</ion-item>
<ion-item *ngIf="due_date.hasError('required') && due_date.touched">
<p>Digite a data *</p>
</ion-item>
</ion-card>
parcelas() {
this.parcelasCobranca = [];
this.valorParcela = this.amount / this.quantidadeParcelas;
for (let i = 0; i < this.quantidadeParcelas; i++) {
this.parcelasCobranca.push({
due_date:this.due_date.value,
value: this.valorParcela,
});
}
console.log(this.parcelasCobranca)
}
Update 1 - follows the other code I made, the due date is going back a few days.
parcelas() {
this.parcelasCobranca = [];
this.valorParcela = this.amount / this.quantidadeParcelas;
let someDate = new Date(this.due_date.value);
for (let i = 0; i < this.quantidadeParcelas; i++) {
someDate.setDate(someDate.getDate() + 30);
let dd = someDate.getDate();
let mm = someDate.getMonth();
let y = someDate.getFullYear();
let someFormattedDate = dd + '-' + mm + '-' + y;
this.parcelasCobranca.push({
due_date: someFormattedDate,
value: this.valorParcela,
});
}
console.log(this.parcelasCobranca)
}
<ion-grid [hidden]="!value">
<ion-card *ngFor="let p of parcelasCobranca; let i = index">
Parcela
<ion-item>
<ion-label stacked>Valor: {{ valorParcela }}</ion-label>
</ion-item>
<ion-item>
<ion-label stacked>Data de vencimento *</ion-label>
<ion-input type="date" formControlName="due_date" name="due_date" id="due_date"></ion-input>
</ion-item>
<ion-item *ngIf="due_date.hasError('required') && due_date.touched">
<p>Digite a data *</p>
</ion-item>
</ion-card>
</ion-grid>
Man, I mean, for the help, that’s what I wanted. But I wanted to ask a question, I had redone the code here, but when I put a date it’s going back a few days. Example, I put the date of the first expiration for the day 30 March, but when I order print on the console the expiration date appears 28 March. I’ll put this code in the post.
– Martin Alves
You’ve done as you are here ?
– NoobSaibot
It’s a little different
– Martin Alves
Use the library Moment js. will facilitate a lot in working with dates, just see both lines of code you wrote and look at that of the answer.
– NoobSaibot