Jump to content

Subtract times in database from current time.


mikeinaustin

Recommended Posts

Hello, I am trying to subtract the current time from a list of times in a mysql database. The first page inserts the time into mysql.

<?php
$var_Time = date("h:i:s");
$mysqli = new mysqli('localhost','root','blah','test');
if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$insert_row = $mysqli->query("REPLACE  INTO test_table (id, time)  Values(NULL, '$var_Time')");
if($insert_row){
    while (false);
}else{
    die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$mysqli->close();
?>

The second page is supposed to iterate through all of the times in the database and subtract the current time, but i cant figure out how to do it.

<?php
$mysqli = new mysqli('localhost','root','blah','test');
if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$query = "SELECT * FROM `test_table`";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$var_set_time = stripslashes($row['time']);
$var_current_time = date("h:i:s");
$diff = strtotime( $var_current_time .' UTC' ) - strtotime( $var_set_time .' UTC');
echo $diff;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.