Eclectic Posted October 6, 2009 Share Posted October 6, 2009 First off Im no Coder. I struggle through and make do most of the time, taking snippets I generally manage to get done what I need and edit. Now I am totally perplexed by the task at hand. Basically I have a small site with a handful of users. I want to check the dates the users login, I have a nice script I found which is calling for what I want. But it dsiplays in UNIXTIMESTAMP. For the life of me I cant figure out how to get it to display in GMT (or any "real" date). I can call a date and convert it to GMT, but not when calling for the users database with and displaying all the logins from a table. Help would be greatly appreciated. Heres the snippet Im using. function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; 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"); $time = mysql_result($result,$i,"timestamp"); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n"; } echo "</table><br>\n"; Thanks. Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/ Share on other sites More sharing options...
nafetski Posted October 6, 2009 Share Posted October 6, 2009 You want to convert a Unix timestamp to a date? There's a function for that http://us.php.net/manual/en/function.date.php Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/#findComment-931885 Share on other sites More sharing options...
Eclectic Posted October 6, 2009 Author Share Posted October 6, 2009 OK, thank you. I have gone about calling the date in a few ways, mostly to the result of what you supplied. But the problem Im having is Im calling from my database for the users last login dates. I have it outputting the UNIX timestamp. Which looks like: 1254863670 Now I want to have that date displayed as a date we know it as. Thats where Im getting stuck, I cant figure out how to call the dates and THEN convert it for all the dates. Im sure it's that I have to add something with the $time var to have it display correctly function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); and echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; 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"); $time = mysql_result($result,$i,"timestamp"); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n"; } echo "</table><br>\n"; What I add there to get the var correct, I really dont know Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/#findComment-931920 Share on other sites More sharing options...
Dathremar Posted October 6, 2009 Share Posted October 6, 2009 You should use this. Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/#findComment-931927 Share on other sites More sharing options...
nafetski Posted October 6, 2009 Share Posted October 6, 2009 echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n"; instead of that, put echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>".date("F dS Y",$time)."</td></tr>\n"; Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/#findComment-931928 Share on other sites More sharing options...
mikesta707 Posted October 6, 2009 Share Posted October 6, 2009 $time = date("F jS, Y", mysql_result($result,$i,"timestamp")); for todays date will produce October 6th, 2009 (tested and works, assuming the data is correct) dam beat me too it Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/#findComment-931931 Share on other sites More sharing options...
Eclectic Posted October 7, 2009 Author Share Posted October 7, 2009 Thanks Nafetski, works perfectly. Now I see how it works Im using, ".date("D, M jS - g:i a",$time) :bow: Link to comment https://forums.phpfreaks.com/topic/176745-convert-mysql-time-string-to-gmt/#findComment-932498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.