Time system remaining [duplicate]

-2

I have a date generator and in it I mark the day that a certain event will happen. As seen in the image:

Thissystemreturnsavalueintime().Ineedacodethatsaystheremainingtime,forexample,isnow:9/3/2016-19:26andtheeventwasscheduledfor-9/3/2016-9:00p.m.

Iwantthecodetoreturntheremainingtime.Forexample:2days,1hourand10minutesareleft.

Herearesomedatestohelpwhendoing:

23/03/201606:00-time()-1458723600

03/15/201609:00-time()-1458043200

ItriedtoadaptthecodetooneIalreadyhave,butitdidnotwork.

IhavethiscodethatdoestheoppositeofwhatIwant,itshowsthetimethathaspassed.

functiontempo($time){$diff=time()-$time;$seconds=$diff;$minutes=round($diff/60);$hours=round($diff/3600);$days=round($diff/86400);$weeks=round($diff/604800);$months=round($diff/2419200);$years=round($diff/29030400);if($seconds<10)return"Agora mesmo";
        if($seconds < 60) return "$seconds segundos";
        else if($minutes < 60) return $minutes==1 ?'1 minuto':$minutes.' minutos';
        else if($hours < 24) return $hours==1 ?'1 hora':$hours.' horas';
        else if($days < 7) return $days==1 ?'1 dia':$days.' dias';
        else if($weeks < 4) return $weeks==1 ?'1 semana':$weeks.' semanas';
        else if($months < 12) return $months == 1 ?'1 mes':$months.' meses';
        else return $years == 1 ? '1 ano':$years.' anos';
    }

It returns values of type: 1 hour ago, 10 minutes ago, Now, etc. ...

    
asked by anonymous 09.03.2016 / 23:32

1 answer

2

Exchange:

$diff = time() - $time;

By

$diff = $time - time();
    
11.03.2016 / 19:24