Jump to content


Photo

date difference ...


  • Please log in to reply
9 replies to this topic

#1 sun14php

sun14php
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 June 2006 - 08:27 AM

look at below: my data stored in mysql table.

LogId Date         Time     SrvID    Problem Deatils       Action     Status(5 min) Status TimeTaken    Rmarks
54 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





#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 June 2006 - 08:43 AM

//$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

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 June 2006 - 08:50 AM

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>";

?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 June 2006 - 08:57 AM

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.
Think you're smarty?

(Gone until 20 to November)

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 June 2006 - 09:01 AM

orio can you kindly brake your code right down please and post it without the [code tags] cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 June 2006 - 09:40 AM

//$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
Think you're smarty?

(Gone until 20 to November)

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 June 2006 - 09:49 AM

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;
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 sun14php

sun14php
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 June 2006 - 10:49 AM

no orio i could not get ur script . please explain per my first query:

how do i display time in minutes only ?


#9 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 June 2006 - 11:17 AM

//$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.net

if($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);
 

Any further questions?

Orio.
Think you're smarty?

(Gone until 20 to November)

#10 sun14php

sun14php
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 June 2006 - 12:33 PM

Orio,

  U saved me Really.

Thanx 3 trucks of thanx with best wishes.  :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users