How to check how many days passed from a Javascript date

Asked

Viewed 778 times

-2

I need to check the amount of days that have passed since the day a 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 do a control so that in 04 days, for example, the user is warned that he is with a delayed task, my need then, is to know how I can check via the system date if already passed the four days, the logic would be dataAtual - dataCriacao = 4 or ou dataCricao + 4 = dataAtual but I’m not able to accomplish that.

1 answer

1


Take a look in that 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 initial and final date.

  • It worked that way

Browser other questions tagged

You are not signed in. Login or sign up in order to post.