Subtract date with javascript

1

I have the following problem, I have a date that comes from the database and compare with the current date, and I do the following:

var dataAtual = new Date();
var partesData = dataAtual.split("/");
var dataAtualNova = new Date(partesData[2], partesData[1] - 1, partesData[0]);
var dataassinado = new Date({vem do banco});

if(dataAtualNova < dataassinado){ //faça algo }

But the current date is for example 17/05/1995 and date coming from the bank comes 17/05/1995 10:45 so if the dates are equal the date that comes from the bank will always be greater than the current date because of the hours, how can I match or take the time?

    
asked by anonymous 01.12.2016 / 19:11

2 answers

3

Using javascript only

var data1 = new Date(2016, 11, 1, 16, 15, 30); // 01/12/2016 16:15:30
var data2 = new Date(2016, 11, 1); // 01/12/2016 00:00:00

console.log('Comparando com as horas, elas são diferentes:');
console.log(data1.getTime() === data2.getTime());

data1.setHours(0, 0, 0, 0);

console.log('Sem as horas, são iguais.');
console.log(data1.getTime() === data2.getTime());
    
01.12.2016 / 19:34
2

If the date you have is in this 17/05/1995 10:45 format, you can sort by space and get only the date:

var somenteData = "17/05/1995 10:45".split(" ")[0]; // 17/05/1995 10:45 > 17/05/1995
    
01.12.2016 / 19:20