MyBB Community Forums
Time Online - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Support (https://community.mybb.com/forum-72.html)
+---- Thread: Time Online (/thread-8150.html)



Time Online - Maverickb7 - 2006-04-10

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!


RE: Time Online - zaher1988 - 2006-04-10

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


RE: Time Online - Maverickb7 - 2006-04-10

Alright... how would I put the first group of code into play? (Note: I'm using this within a file outside my forum directory)


RE: Time Online - Michael S. - 2006-04-10

It is easier to use the MyBB function as it already exists:
require("./pathtomybb/global.php");
$timeonline = nice_time($timefromdb);



RE: Time Online - zaher1988 - 2006-04-10

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



RE: Time Online - Maverickb7 - 2006-04-10

Alright Thanks. I've managed to get it working nicely. Smile Much appreciated.