Php date in gmt help

Hello forums

I am trying to log to a mysql dbase the exact time a user logs in including seconds with this:

$time_in = gmdate('Y-m-d H:i:s');

$ad = mysql_query("INSERT INTO sd_record (id, time_in) VALUES ('$id', '$time_in') ;

Which will insert something like this in the database:
2010-05-05 15:59:15
(my database table is set to datetime with a default value of 0000-00-00 00:00:00)

Question :

When I retrieve this back how can I format it with GMT+8
the code below doesn’t work:

//database query select time_in from blah blah 

$time_in = gmdate('M d, Y l | h:i:s', strtotime($r['time_in']));
echo  $time_in

the above code is giving me
May 05, 2010 Wednesday | 03:59:15

how do I correct this to give me the right time w/c is
May 05, 2010 Wednesday | 12:59:15

Tnx in advance

You should do it in the SQL…

INSERT INTO sd_record ( id, time_in ) VALUES ( $id,  UTC_TIMESTAMP() )
SELECT id, DATE_FORMAT( CONVERT_TZ(time_in, 'GMT', '+8:00'), '%M %e, %Y %W | %r' ) as time_in FROM sd_record WHERE id = $id

Thanks logic_earth , somehow the ‘GMT’ in the query is returning NULL I used this instead:

DATE_FORMAT( CONVERT_TZ(time_in, ‘+00:00’, ‘+8:00’), ‘%M %e, %Y %W | %r’ )

It works just fine though I’m just wondering if it’s the right thing