Jump to content

Recommended Posts

This problem has been driving me crazy for most of this morning. I wrote a table that took the following information from each user of a database and placed them in a database: username, user level, email, last active, and date registered. You can see a table of this here.

 

For each of the entries in the "Last Active" and "Registered" columns, the first line shows the unix timestamp, and the second line should show the time and date based on that. But it's not doing that correctly. The hour and minutes are correct for each one, but the month, day, and year is the exact same for each!! For each one, it says "Jul 07, 2009". I have no idea where Jul 07 even came from! What in the world is going on?

 

This is the code for test.php:

 

<?
include("header.php");

function displayUsers(){
global $database;
$q = "SELECT username, userlevel, email, timestamp, dateRegistered FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
$result = $database->query($q);
/* Error occurred, return given name by default */
$num_rows = mysql_numrows($result);

/* Display table contents */
echo "<table class=\"users\">";
echo "<tr> <th>Username</th> <th>Level</th> <th>Email</th> <th>Last Active</th> <th>Registered</th> </tr>";
for ($i=0; $i<$num_rows; $i++) {
	$uname     = mysql_result($result, $i, "username");
	$ulevel    = mysql_result($result, $i, "userlevel");
	$email     = mysql_result($result, $i, "email");
	$lasttime  = mysql_result($result, $i, "timestamp");
	$regtime   = mysql_result($result, $i, "dateRegistered");

	$lasttime = (int)$lasttime;
	$regtime  = (int)$regtime;

	echo "<tr> <td>______________</td> <td>$ulevel</td> <td>______________</td> <td>$lasttime<br>".date("H:i, M m, Y", $lasttime)."</td> <td>$regtime<br>".date("H:i, M m, Y", $regtime)."</td> </tr>";
}
echo "</table>";
}

displayUsers();

include("footer.php");
?>

date("H:i, M m, Y", $lasttime)

 

H  24-hour format of an hour with leading zeros  00 through 23

i  Minutes with leading zeros  00 to 59

M  A short textual representation of a month, three letters  Jan through Dec

m  Numeric representation of a month, with leading zeros  01 through 12

Y  A full numeric representation of a year, 4 digits  Examples: 1999 or 2003

 

Pretty obvious where the problem is

date("H:i, M m, Y", $lasttime)

 

H  24-hour format of an hour with leading zeros  00 through 23

i  Minutes with leading zeros  00 to 59

M  A short textual representation of a month, three letters  Jan through Dec

m  Numeric representation of a month, with leading zeros  01 through 12

Y  A full numeric representation of a year, 4 digits  Examples: 1999 or 2003

 

Pretty obvious where the problem is

 

I don't understand. The format I have it use is correct. I need something like 14:47, Jul 27, 2009, but while the hour and minute is correct, the month, day, and year is stuck on July 7, 2009.

date("H:i, F d, Y", $lasttime)

 

d  Day of the month, 2 digits with leading zeros  01 to 31

D A textual representation of a day, three letters Mon through Sun

j Day of the month without leading zeros 1 to 31

 

F  A full textual representation of a month, such as January or March  January through December

M    A short textual representation of a month, three letters    Jan through Dec

 

So you can change F to M, but you need the d for the DAYS

:facewall:

 

M    A short textual representation of a month, three letters    Jan through Dec

m    Numeric representation of a month, with leading zeros    01 through 12

 

:examine:

 

God am I stupid...

I just quickly looked for "day" on php.net's Date page and just saw "01 through something..." and used that. Sigh. Thanks a lot for clearing that up.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.