Hi,

I'm trying to substract the hours of the time with the hours of the begining of an event, and print how many time is left.

Can someone help me?

//Preço Viagens
$partida=$viagens['HoraPartida'];

$horapartida = explode(":", $partida);
echo $horapartida[0];

$horasistema = date("G");   //hora sistema

$difhoras=$horasistema - $horapartida;

can you please tell what data was there in $viagens['HoraPartida'].

Because until that we can't tell solution to your problem.

can you please tell what data was there in $viagens['HoraPartida'].

My guess would be a time string in hours and minutes: "hh:mm". A better question would be what result is the OP expecting and how does the code not produce the correct result?

This works fine:

    $partida = "10:23";
    $horapartida = explode(":", $partida);
    print "horapartida: " . $horapartida[0] . "\n";;
    $horasistema = date("G"); //hora sistema
    $difhoras=$horasistema - $horapartida[0];
    print "Difhoras: " . $difhoras . "\n";

Notice that the OP was missing the array element selector [] in
his original line 9.

Regards,
Shawn

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.