Hello-- I've been trying to figure out how I would go about convert the data inside the timeonline column in the mybb_users table to show as X hours, X Minutes, and X Seconds. Does anyone know how I coudl convert the number saved to the database column? If someone could provide some code or help I would appreciate it. Thanks!
Hello there,
that time number you are talking about is UNIX Time Stamp,
To convert it you will need to use
$ysecs = 365*24*60*60;
$mosecs = 31*24*60*60;
$wsecs = 7*24*60*60;
$dsecs = 24*60*60;
$hsecs = 60*60;
$msecs = 60;
$years = floor($stamp/$ysecs);
$stamp %= $ysecs;
$months = floor($stamp/$mosecs);
$stamp %= $mosecs;
$weeks = floor($stamp/$wsecs);
$stamp %= $wsecs;
$days = floor($stamp/$dsecs);
$stamp %= $dsecs;
$hours = floor($stamp/$hsecs);
$stamp %= $hsecs;
$minutes = floor($stamp/$msecs);
$stamp %= $msecs;
$seconds = $stamp;
However MyBB has a
function that will do the job
nice_time($timetoconvert)
time to convert is the actuall time you want to convert wheter it was already set manually or retrived from a database etc...
regards
Alright... how would I put the first group of code into play? (Note: I'm using this within a file outside my forum directory)
It is easier to use the MyBB function as it already exists:
require("./pathtomybb/global.php");
$timeonline = nice_time($timefromdb);
first from where you are trying to retrieve the time stamp? from the same database? or from a file? anyway, you will need a query something like
$query = mysql_query("SELECT time, user FROM tableprefix_urtable WHERE user='zz' ");
$var = mysql_fetch_array ($query)
so let's assume that date is a unix time, the variable will become
$stamp = $var['time'];
so use $stamp along with the above code. and the final thing will look as
echo "$years years , $months months , $days days , $hours hours";
however try to include
./inc/functions.php and use the Mybb funtion nice_time ....
regards
Alright Thanks. I've managed to get it working nicely.

Much appreciated.