eugeniu Posted July 27, 2009 Share Posted July 27, 2009 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/ Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884202 Share on other sites More sharing options...
eugeniu Posted July 27, 2009 Author Share Posted July 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884218 Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884221 Share on other sites More sharing options...
MadTechie Posted July 27, 2009 Share Posted July 27, 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 Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884227 Share on other sites More sharing options...
eugeniu Posted July 27, 2009 Author Share Posted July 27, 2009 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884232 Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 Not stupid, just looking for a more complicated answer Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884235 Share on other sites More sharing options...
eugeniu Posted July 27, 2009 Author Share Posted July 27, 2009 Not stupid, just looking for a more complicated answer Yeah, I guess so . Quote Link to comment https://forums.phpfreaks.com/topic/167659-solved-date-not-working-properly-please-help/#findComment-884301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.