newbtophp Posted August 12, 2010 Share Posted August 12, 2010 I have an idea, which I'm trying to realise, im using the time() function to store the timestamp within my db...and within the db I have a timezone column (which contains the timezone selected by that user). So I'd like to display $row['timestamp'] (the stored timestamp generated by time()) to the specified timezone, how would that work? <?php //$timestamp = timestamp generated by the time() function //$timezone = the timezone to convert $timestamp too function convert_time($timestamp, $timezone) { //$new_timestamp = do something to adapt $timestamp to $timezone //return the formatted/readable date... return date('D M Y H:i', $new_timestamp); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210516-format-timestamp-to-timezone/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 12, 2010 Share Posted August 12, 2010 Too bad you didn't store the time using a DATETIME or mysql TIMESTAMP, because you can do this directly in your query using the mysql CONVERT_TZ() function - CONVERT_TZ('2004-01-01 12:00:00','GMT','MET'); You could probably use the mysql FROM_UNIXTIME() function to get your data into a format that would work. Quote Link to comment https://forums.phpfreaks.com/topic/210516-format-timestamp-to-timezone/#findComment-1098390 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.