#Dear, I have been trying to calculate today's date with the technical_review_expiry_date. I want you to calculate how many days are left. With this function diff does the calculation. But how can I do it if it is a fix.
<?php
require("Conexion/revision_tecnica.php");
$todayDate=new DateTime('now');
$sentencia =("SELECT id_revision_tecnica,patente_camion,fecha_revision_tecnica,fecha_vencimiento_revision_tecnica FROM revision_tecnica
INNER JOIN tracto on tracto.id_tracto=revision_tecnica.tracto_id_tracto");
$data = $base->query($sentencia)->fetchAll(PDO::FETCH_ASSOC);
$todayDate=new DateTime('now');
$fechas = array();
foreach($data as $datos) {
echo $fechas[]= $datos['fecha_vencimiento_revision_tecnica'].'<br />';
}
echo json_encode( array('data'=>$data) );
?>
You could create two objects
DateTime
, one with each date, and then usediff
to compute the difference between the two.For example:
Departure:
Here,
$mDiff
it is an object of typeDateInterval
, and you can use it for more things, like knowing the number of years, months, hours, minutes, seconds... and you can also use it withformat()
.