Jump to content

Convert unix time from mysql DB to realtime


MadFly
 Share

Recommended Posts

I have a mysql database, where user activity is recorded. currently the data/time in database is displayed as 1334072381 How can i convert that specific date / time to realtime, so that it reads like 11 April 2012, 20:42:51 Currently I have a php page, that has lots of code, including this:

echo "<td align='center'>" . date('j F Y, H:i:s') . "</td>";

but for ALL users it displays the same time, even though i know, certain users was not active for at least a week... Any help?

Link to comment
Share on other sites

I am having some difficulty completely understanding what you said...

date

('j F Y, H:i:s')

are these two seperate parameters? If so, how do I tell date('j F Y, H:i:s') to convert 1334072381 to j F Y, H:i:s I have something in mind like this:

$acct_lastlogin_time = 'j F Y, H:i:s'; echo "<td align='center'>" . date($acct_lastlogin_time) . "</td>";

The table that contains the time values is acct_lastlogin_time without any conversion, i get this output

pm2012-04-11T21:15:03+00:002012-04-11T21:15:03+00:0030_Wednesdaypm0330Wednesday20129154_301504UTC

Edited by MadFly
Link to comment
Share on other sites

are these two seperate parameters?
No, date is the name of the function you're calling and everything inside the quotes is the first parameter you're sending to the function. A second parameter would go after the first one, with a comma between them. date('j F Y, H:i:s', 1334072381)
Link to comment
Share on other sites

ah ok, that makes sense.almost there... could you possibly tell me how can i replace that 1334072381 with something that gets this number based on user id? Something like this...

$unixtime="SELECT acct_lastlogin_time FROM $db WHERE uid = '".$q."'";

I used this tutorial on w3scools

Link to comment
Share on other sites

http://www.w3schools.com/php/php_mysql_select.asphttp://www.w3schools.com/php/func_mysql_fetch_assoc.asp after that it should be a matter of accessing the index out of the returned results set, similar to the example that outputs the entire result
echo $result['acct_lastling_time'];

http://www.w3schools.com/php/php_arrays.asp

Link to comment
Share on other sites

it's not that hard, you just need to understand/follow the steps. Everything is in the links/tutorials. Make query (SELECT) to the table in the database (mysql_query). You then get a result set.From the result set, you have to extract the data out of it in a meaningful way, (mysql_fetch_assoc or mysql_fetch_array). Use array syntax to reference the member/key you are looking for.

Link to comment
Share on other sites

Took about a minute to make this, you can use this as reference, but this is pretty much what you need:

$sql ="SELECT acct_lastlogin_time FROM $db WHERE uid = '".$q."'";$qry = mysql_query($sql);$result = mysql_fetch_array($qry);echo date('j F Y, H:i:s', $result['acct_lastlogin_time']);

Edited by Err
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...