lalabored Posted January 19, 2008 Share Posted January 19, 2008 I have a membership system and I want to implement time zones so that users can choose their own time zones and the times in my database will be different for users of different time zones. How would I do this? Please help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/86813-solved-time-zones/ Share on other sites More sharing options...
toplay Posted January 19, 2008 Share Posted January 19, 2008 The date and time in the database should always be the same timezone (your servers). You just display it based on what user sets. Save with each user the ability to identify their timezone, or +/- hours from your servers timezone. Then you calculate the date and time and display it. Please search these forums and google the web because this has been discussed so many times. http://www.google.com/search?hl=en&q=timezones+%2Bphp http://jokke.dk/2007/07/timezones_in_mysql_and_php http://www.expertsrt.com/tutorials/Matt/PHPTimeZone.html Quote Link to comment https://forums.phpfreaks.com/topic/86813-solved-time-zones/#findComment-443692 Share on other sites More sharing options...
pkSML Posted January 20, 2008 Share Posted January 20, 2008 You could store everything using unix time, which can be accessed by time(); We'll say the user is GMT +500 and the original time is held in $orig_time, so format your date like this: echo date("l, F j, Y - G:i:s ", ($orig_time - (5*3600))); Quote Link to comment https://forums.phpfreaks.com/topic/86813-solved-time-zones/#findComment-443964 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 If you want to store the data in an SQL Datetime field then you need to use the following date() format: 'Y-m-d H:i:s' Quote Link to comment https://forums.phpfreaks.com/topic/86813-solved-time-zones/#findComment-443966 Share on other sites More sharing options...
toplay Posted January 20, 2008 Share Posted January 20, 2008 You could store everything using unix time... Too many people on here think that it's best to store in a MySQL table a unix based timestamp. I disagree. Use MySQL DATETIME data type instead. It allows you to use a lot of MySQL date and time functions: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-add And if you still need a unix timestamp you can still get one out of DATETIME column simply by using UNIX_TIMESTAMP() MySQL function. Quote Link to comment https://forums.phpfreaks.com/topic/86813-solved-time-zones/#findComment-443971 Share on other sites More sharing options...
toplay Posted January 20, 2008 Share Posted January 20, 2008 If you want to store the data in an SQL Datetime field then you need to use the following date() format: 'Y-m-d H:i:s' I prefer to simply use the NOW() MySQL function when wanting to insert the current date and time. Quote Link to comment https://forums.phpfreaks.com/topic/86813-solved-time-zones/#findComment-443977 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.