php - Weird result when taking date from mysql -


i want substract 2 dates , take result in minutes code bellow gives me answer want.

$to_time = strtotime("2017-03-27 17:31:40");   $from_time = strtotime("2017-03-27 18:32:40");   echo "sunolo1: ".round(abs($to_time - $from_time) / 60,2). " minute"; 

but when try retrieve dynamically date mysql using php doesnt work returns 0. (date in table in timestamp)

 $d = new datetime("now", new datetimezone("europe/athens"));      $datem = $d->format("y-m-j h:i:s");     $result = mysqli_prepare($con, "select date mytable id= ? ");        mysqli_stmt_bind_param($result, 'i', $ids);        mysqli_stmt_execute($result);        mysqli_stmt_bind_result($result, $ddd);    while(mysqli_stmt_fetch($result)){     $sunolo_krathshs = round(abs($ddd - $datem) / 60,2);     echo "sunoloo: ".$sunolo_krathshs;   } 

you need parse value of $ddd datetime object, since easiest way compare datetime objects.

$date = new datetime(); $ddd = $date->settimestamp($ddd);  $sunolo_krathshs = round(abs($ddd - $d) / 60,2); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -