MyBB Community Forums

Full Version: Output 'lastactive' as a date?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I convert the date format that is in lastactive in the database to a date format like month/day/year?

I would be using it in a table i.e. <?php echo ""; ?>

I am making a table (personal use) that outputs users and last active dates.

Thanks for your help.
I've done it like:

$memlastvisitdate = my_date($mybb->settings['dateformat'], $rowusr['lastactive']);
$memlastvisittime = my_date($mybb->settings['timeformat'], $rowusr['lastactive']);

where my_date is a mybb default function
and
$rowusr['lastactive']) is the data received out of the mysql.
(rowusr can be everything, as long as you've defined it before).
AdminCP > Configuration > Date and Time Formats > in "Date Format" option field, change the value to;
m/d/Y

Notice: It'll effect the whole forum's date format.
I was going to be using a php file that I could access that generates my table outside of MyBB.

I think I've got it.

<?php
define ('DB_USER', '');
define ('DB_PASSWORD', '');
define ('DB_HOST', '');
define ('DB_NAME', '');

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die('Failure: ' . mysql_error() );
mysql_select_db(DB_NAME) or die ('Could not select database: ' . mysql_error() );

?>
<style type="text/css">
<!--
body {
	background-color: #CCCCCC;
}
-->
</style></head>

<body>

<?PHP
mysql_select_db("");

$num = 0;
$time_now = time();

$result = mysql_query("SELECT * FROM mybb_users ORDER BY `lastactive` DESC");

echo "<table border='1'>
<tr>
<th>number</th>
<th>Username</th>
<th>email</th>
<th>Last Visit</th>
<th>Last Post</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
$num++;
$age = $time_now - $row['lastactive'];
$age = round($age/86400);
$post = round(($time_now - $row['lastpost'])/86400);
  echo "<tr>";
  echo "<td>" .$num . "</td>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" .$age. "</td>";
  echo "<td>" .$post. "</td>";
//  echo "<td>" . "</td>";
  echo "</tr>";
  }
echo "</table>";
//echo $time_now;
mysql_close();

?>
Why not including MyBB file and use the variables available there?
http://community.mybb.com/thread-116043.html
http://community.mybb.com/thread-116225.html
Because I don't need to learn anything new. :^)

I'm slowly learning php (Object Oriented is still on my to learn list).