newbie help
Moderator: General Moderators
newbie help
How can i subtract time ?
ex. 23:30:15 - 18:15:35
thanks!
ex. 23:30:15 - 18:15:35
thanks!
Use UNIX time expression
[php_man]mktime()[/php_man] function to create the UNIX time number more on that on the manual:-
Format using the [php_man]date()[/php_man] function:-
[php_man]mktime()[/php_man] function to create the UNIX time number more on that on the manual:-
Code: Select all
<?php
$date1 = mktime(23,30,15,0,0,0);
$date2 = mktime(18,15,35);
$date3 = $date1 - $date2;
?>Code: Select all
<?php
$date3 = date("H:i:s" ,$date3);
?>Well if you have the values as you said in a variable. Split the values using explode().
Code: Select all
<?php
$time = "23:30:15"; // assuming that it is in hh:mm:ss format
$time = explode(":", $time);
// $time[0] = hour
// $time[1] = minute
// $time[2] = seconds
?>Something like:
Code: Select all
$time1 = '23:30:15';
$time2 = '18:15:35';
list($hour, $minute, $second) = explode(':', $time1);
$t_time1 = mktime($hour, $minute, $second);
list($hour, $minute, $second) = explode(':', $time2);
$t_time2 = mktime($hour, $minute, $second);
echo date('h:i:s', $t_time1 - $t_time2);why is it i always got a wrong result.
data are :
time in : 17:22:04
time out : 17:22:06
result : 01:22:06
my code
PLEASE USE BBCODE TO HIGHLIGHT YOUR PHP...THANKS (BECH100)
data are :
time in : 17:22:04
time out : 17:22:06
result : 01:22:06
my code
Code: Select all
$today = date("H:i:s");
include "./connect.php";
$connect = mysql_pconnect($dbhost,$dbusername,$dbuserpassword);
$result = mysql_db_query($dbname,"SELECT * from asian_field where code = '$code'");
$time1 = $row["timein"];
$time2 = $today;
list($hour, $minute, $second) = explode(':', $time1);
$t_time1 = mktime($hour, $minute, $second);
list($hour, $minute, $second) = explode(':', $time2);
$t_time2 = mktime($hour, $minute, $second);
$total = date('h:i:s', $t_time2 - $t_time1);
$query = "update asian_field set timeout = '$today', elapse_time = '$total' where code = '$code'";
$result = mysql_db_query($dbname,$query);MOD MSG: PLEASE USE THE BBCODE TO HIGHLIGHT YOUR PHP! THANKS
result :
in : 17:39:14
out : 17:39:15
result : 08:00:01
result :
in : 17:39:14
out : 17:39:15
result : 08:00:01
Code: Select all
<?
$today = date("H:i:s");
include "./connect.php";
$connect = mysql_pconnect($dbhost,$dbusername,$dbuserpassword);
$result = mysql_db_query($dbname,"SELECT * from asian_field where code = '$code'");
$row = mysql_fetch_array($result);
$time1 = $row["timein"];
$time2 = $today;
list($hour, $minute, $second) = explode(':', $time1);
$t_time1 = mktime($hour, $minute, $second);
list($hour, $minute, $second) = explode(':', $time2);
$t_time2 = mktime($hour, $minute, $second);
$total = date('h:i:s', $t_time2 - $t_time1);
$query = "update asian_field set timeout = '$today', elapse_time = '$total' where code = '$code'";
$result = mysql_db_query($dbname,$query);
?>Bech100 wrote:Don't worrydyowel wrote:sorry admin
Try echoing $time1 and $time2 to make sure they are the times you expect.
Post back saying what they were.
Mark
Hi guys its me again.. i think i know waht the problem is. Its the conversion of seconds into time. I have echoed the $time1, $time2 and the result.
data :
time1 : 09:51:33
time2 : 09:51:35
result : 2
How can i convert the seconds into time format?