Timestamp difference in PHP mysql -


i want exact time difference between 2 php timestamps. & m using code

code 1:

   $d1=strtotime(date('h:i:s'));      //current time consider e.g 15:00:00    $d2=strtotime('18:00:00');     $all = round(($d2 - $d1) / 60);    $d = floor ($all / 1440);    $h = floor (($all - $d * 1440) / 60);    $m = $all - ($d * 1440) - ($h * 60); 

& if print $h & $m - m looking , difference between 2 timestamps.

now want $d2 table ..

i have stored timestamp in mysql table datatype time .

as below

code 2

    $d1=strtotime(date('h:i:s'));      //current time consider e.g 15:00:00  $d2=strtotime($rows['showtime']);  //where $rows['showtime'] timestamp stored in mysql table. consider 18:00:00  $all = round(($d2 - $d1) / 60); $d = floor ($all / 1440); $h = floor (($all - $d * 1440) / 60); $m = $all - ($d * 1440) - ($h * 60); 

but when print $h & $m m not getting values properly... please 1 me so...

code 1 works when try execute code2 shows garbage values not values m expecting.

please please please.

following correct answer question

  $d1=strtotime(date('h:i:s'));      //current time consider e.g 15:00:00    $d2=strtotime($rows['showtime']);  //where $rows['showtime'] timestamp stored in mysql table. consider 18:00:00    $all = round(abs($d2 - $d1) / 60);   $d = floor ($all / 1440);   $h = floor (($all - $d * 1440) / 60);   $m = $all - ($d * 1440) - ($h * 60); 

use abs() on there.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -