0
I am making a business rule in which the customer’s checkin can never be less than the previous day. but I’m just finding the difference between days, and in this case the values are the same for days past and days past, for example:
Dia atual: 11/02/2021
Checkin: 10/02/2021
Resultado: 1 dia
Dia atual: 11/02/2021
Checkin: 12/02/2021
Resultado: 1 dia
function calcularData(dataAtual, checkIn) {
const dataatual = new Date(inverterData(dataAtual));
const checkin = new Date(inverterData(checkIn));
const timeDiff = Math.abs(checkin.getTime() - dataatual.getTime());
const diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
return diffDays
}
function inverterData(date) {
const regex = '^([0-9]{2})([0-9]{2})([0-9]{4})';
const dataFormatada = date.match(regex);
return `${dataFormatada[2]}/${dataFormatada[1]}/${dataFormatada[3]}`;
}
console.log(calcularData('11022021','10012021'))