I'm writing code to subtract two dates. It is for a contract type thingy, where user gets to see the number of days left for his contract to complete. Something like start_date_time="today"
and end_date_time=y
where the value of y
is retrieved from the database (DATETIME type). It is in the mysql datetime format (yyyy-mm-dd HH:mm:ss
).
<?php
include_once '../include/connections.php';
$id =$_REQUEST['uid'];
$result= mysql_query("SELECT * FROM data WHERE uid = '$id'");
$test = mysql_fetch_array($result);
echo $test[14];
echo "<br /><br />";
$today=time();
$enddate=strtotime('$test[14]');
$timediff = $enddate - $today;
$days=intval($timediff/86400);
$remaining=$timediff%86400;
$hours=intval($remaining/3600);
$remaining=$remaining%3600;
$mins=intval($remaining/60);
$secs=$remaining%60;
echo "<br>".$days.' days '.$hours.' hours '.$mins.' minutes and '.$secs.' seconds.';
?>
When I echo $test[14];
, I get the date and time as stored in the database which is
(2012-09-26 00:00:00
)
When i echo $today;
then i get it in this format 1348381896
. Now, how do i convert this format to the one retrieved from the db so that i can subtract the 2 dates and get the number of days and time left?