Transform PHP strtotime in minutes

Asked

Viewed 299 times

0

I am testing a code, to show the difference of date and current time with the variable in minutes

<?php 
    $phpdate = strtotime( $data );
    $mysqldate = date( 'd-m-Y H:i:s', $phpdate );
    $data1 = strtotime($mysqldate);
    $data2 = strtotime("now");
    $data3 = $data1 - $data2;
    echo "<br>".$data3;
?>

With strtotime return in seconds, how do I turn $data3 only in minutes?

  • Would not be $minutos = $data3/60?

  • I found a link that can help you. https://answall.com/questions/176643/converter-formato-hora-em-seconds

2 answers

0

To convert second into minutes just split by 60.

In this case:

echo "<br>".$data3/60;

0

First you can convert into divine minutes the difference value by 60.

($data1 - $data2)/60)

Then subtract this value by 60.

(60 - ($data1 - $data2)/60)

Then convert to integer to not get a decimal value.

(int)(60 - ($data1 - $data2)/60);

Final result:

$phpdate = strtotime( $data );
$mysqldate = date( 'd-m-Y H:i:s', $phpdate );
$data1 = strtotime($mysqldate);
$data2 = strtotime("now");
$data3 = (int)(60 - ($data1 - $data2)/60);
echo "<br>".$data3." minutos";
  • Vlw partner, and in case I want to show in hour after 60 minutes?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.