View Full Version : Calculating time difference
sirtom
08-18-2004, 07:06 PM
I get on date with this code
$tsql = "select aeg from task where type_id=$id ORDER BY aeg DESC LIMIT 1";
$tq = mysql_query ($tsql);
$t_res = mysql_fetch_array ($tq);
$ttime = $t_res[aeg];
Now I want to calculate time difference to this date in days til current moment how can I do it.
wilki
08-18-2004, 07:39 PM
Not sure if this is right, but try something like this:
$tsql = "SELECT aeg,DATEDIFF(aeg,CURDATE()) FROM task WHERE 1";
$tq = mysql_query ($tsql);
$ttime = mysql_fetch_row($tq);
// Select the DATEDIFF part of the query located at index 1
print $ttime[1];
You could put
$tsql = "SELECT aeg,DATEDIFF(aeg,CURDATE()) AS Difference FROM task WHERE 1";
then fetch is associatively from the DB and refer to it as
$ttime[Difference]
but that is just a matter of preference. Hope this is right and I Hope it helps.
Good reference page for this type of stuff is found in the mysql online manual at:
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html
sirtom
08-18-2004, 08:02 PM
Got it this way
$days = floor( (time() - $ttime)/60/60/24 );
Works for me!
Thanks do!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.