Home > Net >  Calculate total minutes and total cost Angular 9
Calculate total minutes and total cost Angular 9

Time:02-23

I have tried many times but I can't.

There are two times:

The first time: 12:30 The second time: 12:45 cost: 5 euros

How can I calculate the total minutes?

total minutes = ??? total cost = total minutes * 5;

<form  (ngSubmit)="f.form.valid && onSubmit()" #f="ngForm"  novalidate>
 <div >  
          <label  for="form6Example3">Ora inizio</label>
          <input type="time"   id="oraInizio"  [(ngModel)]="tel.oraInizio" name="oraInizio"   required/>    
        </div>
        <div >  
          <label  for="form6Example3">Ora fine</label>
          <input type="time"   id="oraFine"  [(ngModel)]="tel.oraFine" name="oraFine"   required/>    
        </div>
 <button  type="submit" >Salva</button>
 </form>

phone calls object:

export class Telefonate {
   oraInizio:string = "";
    oraFine:string = "";
}

can you tell me how i can do it? help me with the code in typescript

CodePudding user response:

it doesn't work for me, when I enter the time in the front end

 <input type="time"   id="oraInizio"  [(ngModel)]="tel.oraInizio" name="oraInizio"   required/>
 <input type="time"   id="oraFine"  [(ngModel)]="tel.oraFine" name="oraFine"   required/> 

{{minutes}}

timeFinal = Number(this.tel.oraFine);
  timeInitial = Number(this.tel.oraInizio);
  minutes:number = Math.abs(this.timeFinal -  this.timeInitial) / (1000 * 60) % 60;

can you help me to write the code?

CodePudding user response:

Did you try this? This is the first result after googling how to get minutes between two times

https://www.codegrepper.com/code-examples/javascript/get minutes between two dates in javascript

  • Related