How to check how many days have passed since a date in Javascript

-2

I need to check the number of days that have passed since the day a particular task was created, for example, if I start a task today I get the following date back:

2017-08-30 11:38:52.168

I need to make a control so that in 4 days, for example, the user is warned that he has a late task, so my need is to know how I can check via system date if the four days have already passed , the logic would be dataAtual - dataCriacao = 4 or ou dataCricao + 4 = dataAtual but I'm not able to do this.

    
asked by anonymous 30.08.2017 / 16:59

1 answer

1

Take a look at this Stack Overflow response

But to make it easier:

function dateDiferencaEmDias(a, b) {
   // Descartando timezone e horário de verão
   var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
   var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());

   return Math.floor((utc2 - utc1) / ( 1000 * 60 * 60 * 24) );
}

Where, the input parameters are the start and end dates.

    
30.08.2017 / 17:08