Este equipo redactor ha estado largas horas buscando soluciones a tus búsquedas, te compartimos la solución y nuestro objetivo es que te resulte de gran apoyo.
Ejemplo 1: php calcula la diferencia de fecha
//get Date diff as intervals $d1=newDateTime("2018-01-10 00:00:00");$d2=newDateTime("2019-05-18 01:23:45");$interval=$d1->diff($d2);$diffInSeconds=$interval->s;//45$diffInMinutes=$interval->i;//23$diffInHours=$interval->h;//8$diffInDays=$interval->d;//21$diffInMonths=$interval->m;//4$diffInYears=$interval->y;//1//or get Date difference as total difference$d1=strtotime("2018-01-10 00:00:00");$d2=strtotime("2019-05-18 01:23:45");$totalSecondsDiff=abs($d1-$d2);//42600225$totalMinutesDiff=$totalSecondsDiff/60;//710003.75$totalHoursDiff=$totalSecondsDiff/60/60;//11833.39$totalDaysDiff=$totalSecondsDiff/60/60/24;//493.05$totalMonthsDiff=$totalSecondsDiff/60/60/24/30;//16.43$totalYearsDiff=$totalSecondsDiff/60/60/24/365;//1.35
Ejemplo 2: diferencia de php entre dos fechas
$date1="2007-03-24";$date2="2009-06-26";$diff=abs(strtotime($date2)-strtotime($date1));$years=floor($diff/(365*60*60*24));$months=floor(($diff-$years*365*60*60*24)/(30*60*60*24));$days=floor(($diff-$years*365*60*60*24-$months*30*60*60*24)/(60*60*24));printf("%d years, %d months, %d daysn",$years,$months,$days);
Ejemplo 3: cómo calcular los días entre dos fechas en php
functiondateDifference($start_date,$end_date)// calulating the difference in timestamps $diff=strtotime($start_date)-strtotime($end_date);// 1 day = 24 hours // 24 * 60 * 60 = 86400 secondsreturnceil(abs($diff/86400));// start date $start_date="2016-01-02";// end date $end_date="2016-01-21";// call dateDifference() function to find the number of days between two dates$dateDiff=dateDifference($start_date,$end_date);echo"Difference between two dates: ".$dateDiff." Days ";?>
Ejemplo 4: restar 2 fechas php
$datetime1=strtotime('May 3, 2012 10:38:22 GMT');$datetime2=strtotime('06 Apr 2012 07:22:21 GMT');$secs=$datetime2-$datetime1;// == $days=$secs/86400;
Comentarios y valoraciones del post
Si te mola la idea, eres capaz de dejar un escrito acerca de qué te ha impresionado de este escrito.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)