Skip to main content
Participant
April 4, 2017
Question

calcular tiempo entre fechas

  • April 4, 2017
  • 2 replies
  • 2104 views

Necesito calcular el tiempo transcurrido entre dos fechas y reportarlo en Años, Meses y Dias. Algo similar a la funcion SIFECHA  de Excel

2 replies

Participant
June 11, 2025

¡Hola Enciso89! Si lo que necesitas es calcular el tiempo transcurrido entre dos fechas y reportarlo en años, meses y días (como la función SIFECHA en Excel), puedes hacerlo fácilmente con código en varios lenguajes. Si estás trabajando con JavaScript, aquí tienes una forma práctica:


function calcularDiferencia(fechaInicio, fechaFin) {
const inicio = new Date(fechaInicio);
const fin = new Date(fechaFin);

let años = fin.getFullYear() - inicio.getFullYear();
let meses = fin.getMonth() - inicio.getMonth();
let dias = fin.getDate() - inicio.getDate();

if (dias < 0) {
meses--;
dias += new Date(fin.getFullYear(), fin.getMonth(), 0).getDate();
}
if (meses < 0) {
años--;
meses += 12;
}

return { años, meses, dias };
}

// Ejemplo de uso:
let resultado = calcularDiferencia('2017-04-04', '2024-06-08');
console.log(`${resultado.años} años, ${resultado.meses} meses, ${resultado.dias} días`);
Esto te dará un resultado similar a SIFECHA, ideal para reportes o cálculos de antigüedad. Si estás usando otro lenguaje (como Python, PHP o Excel), también te puedo pasar una versión específica.

Meenakshi_Negi
Legend
May 8, 2017

Hi Enciso89,

Sorry for the delay in response.

If you are trying to calculate the number of days between two days, please refer the steps provided in these threads with the similar query:

https://acrobatusers.com/forum/forms-acrobat/calculating-number-days-between-two-dates/

Calculating an end date

Check if this helps in answering your questions.

If you are referring to something else, please do let us know.

Regards,

Meenakshi