sun14php Posted June 30, 2006 Share Posted June 30, 2006 look at below: my data stored in mysql table.LogId Date Time SrvID Problem Deatils Action Status(5 min) Status TimeTaken Rmarks54 30-06-2006 13:49:03 #sdla12 cpu 94 server staff informed now i want to calculate filed TimeTaken , that should be calculated as TimeTaken=Time-Current system Time; preferbly in minutes usinh php. guide me please :P Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/ Share on other sites More sharing options...
Orio Posted June 30, 2006 Share Posted June 30, 2006 [code]//$time is hh-mm-ss (hour-min-sec) like 13:49:03//$date is dd-mm-yyyy like 30-06-2006$arr_time=explode(":",$time);$arr_date=explode("-",$date);if($arr_date[2]%4==0){$dst=1;} else{$dst=0;}; //for daylight savings$time_in_db=mktime($arr_time[0],$arr_time[1],$arr_time[2],$arr_date[1],$arr_date[0],$arr_date[2],$dst);$now=time();$time_took=$now-$time_in_db; //this is what you need[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51101 Share on other sites More sharing options...
redarrow Posted June 30, 2006 Share Posted June 30, 2006 If the two times are in the database what wrong with my code please cheers.<?$time="01:00:00";$time_tacken="03:00:00";$checked_out=$time_tacken-$time;echo "<br> this is the time it took $checked_out<br>";?> Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51105 Share on other sites More sharing options...
Orio Posted June 30, 2006 Share Posted June 30, 2006 But it sometimes takes more than one day, redarrow.My script works with a range of unlimited dates (From 1/1/1970 until unlimited). But it returns a timestamp. But then you can use the date() function to return a normal date.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51106 Share on other sites More sharing options...
redarrow Posted June 30, 2006 Share Posted June 30, 2006 orio can you kindly brake your code right down please and post it without the [code tags] cheers. Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51110 Share on other sites More sharing options...
Orio Posted June 30, 2006 Share Posted June 30, 2006 //$time is hh-mm-ss (hour-min-sec) like 13:49:03//$date is dd-mm-yyyy like 30-06-2006$arr_time=explode(":",$time);$arr_date=explode("-",$date);if($arr_date[2]%4==0){$dst=1;} else{$dst=0;}; //for daylight savings$time_in_db=mktime($arr_time[0],$arr_time[1],$arr_time[2],$arr_date[1],$arr_date[0],$arr_date[2],$dst);$now=time();$time_took=$now-$time_in_db; //tells you how many seconds it took Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51126 Share on other sites More sharing options...
redarrow Posted June 30, 2006 Share Posted June 30, 2006 i wont to learn it properly cheers.//$time is hh-mm-ss (hour-min-sec) like 13:49:03//$date is dd-mm-yyyy like 30-06-2006$arr_time=explode(":",$time);// what this mean get the time explode?$arr_date=explode("-",$date);// what this mean get the date exsplode?if($arr_date[2]%4==0) { //exsplin this line please$dst=1;//what this?}else{$dst=0;// what this do?};$time_in_db=mktime($arr_time[0],$arr_time[1],$arr_time[2],$arr_date[1],$arr_date[0],$arr_date[2],$dst);// whats mktime doing?$now=time();//this?$time_took=$now-$time_in_db; Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51128 Share on other sites More sharing options...
sun14php Posted June 30, 2006 Author Share Posted June 30, 2006 no orio i could not get ur script . please explain per my first query:how do i display time in minutes only ? Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51142 Share on other sites More sharing options...
Orio Posted June 30, 2006 Share Posted June 30, 2006 [code=php:0]//$time is hh-mm-ss (hour-min-sec) like 13:49:03//$date is dd-mm-yyyy like 30-06-2006$arr_time=explode(":",$time);// Lets say the time is 13:49:03 it'll create an array (keys from 0-2) that its values are 13,49,03. It splits with explode, sperator is ":". Read more about explode on ww.php.net$arr_date=explode("-",$date);// Lets say the date is 30-06-2006 it'll create an array (keys from 0-2) that its values are 30,06,2006. It splits with explode, sperator is ":". Read more about explode on ww.php.netif($arr_date[2]%4==0) { //Check if the modular of the year when you devide it by 4, to see if it's a leap year.$dst=1; //daylight savings is true}else{$dst=0;//daylight savings is false};$time_in_db=mktime($arr_time[0],$arr_time[1],$arr_time[2],$arr_date[1],$arr_date[0],$arr_date[2],$dst); //mktime- creats a timestamp when you give it a date. Read more on www.php.net$now=time(); //Get the current timestamp. Read more on www.php.net$time_took_secs=$now-$time_in_db; //decrease from the current timestamp the timestamp we made with mktime.//if you want to see how many mins:time_took_mins=round($time_took_secs/60);[/code][hr]Any further questions?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51149 Share on other sites More sharing options...
sun14php Posted June 30, 2006 Author Share Posted June 30, 2006 Orio, U saved me Really.Thanx 3 trucks of thanx with best wishes. :D Quote Link to comment https://forums.phpfreaks.com/topic/13272-date-difference/#findComment-51177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.