SQL + Timestamps + PHP

Hi guys, i’m having some problems with one of my scripts and i’m trying to solve it. Basically in my SQL table i’ve got unix timestamps that I need to grab and then display on my webpage.

The SQL query I am running is[php]$sql = “SELECT SID,Subscription,id,TimeStampExpire,
CAST(MID(SID,9,1) AS UNSIGNED) + CAST(‘76561197960265728’ AS UNSIGNED) + CAST(MID(SID, 11,10)*2 AS UNSIGNED) AS friendid
FROM users
WHERE Subscription = ‘Donator Status’
ORDER BY id DESC”;[/php]

TimeStampExpire is the timestamp I want to display, but when I output it via
[php]’.$info[‘TimeStampExpire’].’[/php]
it just shows me the timestamp. How can I format it properly? This has been bugging me for ages, is it to do with the SQL query?

It helps if we can see your code not just 2 parts

Yea sure, sorry!

[php]<?php
// the cache
include “cache.php”;

// includes the connection file
include “donatorconnect.php”;

$ch = new cache();
//find the data

//prepare the query
$sql = “SELECT SteamID,Subscription,id,TimeStampExpire,
CAST(MID(SteamID,9,1) AS UNSIGNED) + CAST(‘76561197960265728’ AS UNSIGNED) + CAST(MID(SteamID, 11,10)*2 AS UNSIGNED) AS friendid
FROM users
WHERE Subscription = ‘Donator Status’
ORDER BY id DESC”;

//perform the query and store the resource in ‘$query’
$query = mysql_query($sql);

//see if there are any results at all
if(mysql_num_rows($query) > 0)
{
//there is one or more results, start printing the table
print ’



Welcome to the player list. This list shows all of our current Donators on our servers.
You can view a players profile, or add them as a friend to your Steam account by clicking on one of the links below!

';
//fetch every possible row from the resource and do nice stuff with it

while($info = mysql_fetch_assoc($query))
{
//convert the steamid into a community id
$community_id = ((substr($info[‘SteamID’], 10)) * 2) + 1197960265728 + (substr($info[‘SteamID’], 8, 1));

	$community_id = '7656'.$community_id; 
    
    //create a link to the Steam community profile
    $site = 'http://steamcommunity.com/profiles/'.$info['friendid']; 
	


    //print the table row with all the info
    print '<tr><td><img src="http://badges.steamprofile.com/profile/simple/steam/'.$info['friendid'].'.png" ></td><td align="center"><a 	href="steam://friends/add/'.$info['friendid'].'">Add as Friend</a></td><td 					align="center"><a href='.$site.'>Steam Community Page</a></td><td>'.$info['Subscription'].' expires on '.$info['TimeStampExpire'].'</td></tr><tr><td colspan="4"><hr></td></tr>'; 
}
//close the table
print '</table><br><div align="center"><p><small>Hello!<br></div></div>';

}
//there are no results
else print ‘No results’;

$ch->close();

?>

[/php]

Is the output a unix timestamp or the formatted date of an sql timestamp field. (“1290329030” or “2011-11-22 19:31:23”)

I would say UNIX as you can copy and paste it into an online UNIX converter. So something like 1290329030 as you said.

In which case, replace:
[php]$info[‘TimeStampExpire’][/php]

with:
[php]date(‘jS M Y’,$info[‘TimeStampExpire’])[/php]

For what to use in the first parameter of the date function, see this page:
http://uk3.php.net/manual/en/function.date.php

Sponsor our Newsletter | Privacy Policy | Terms of Service