Nothadoth Posted August 2, 2012 Share Posted August 2, 2012 Hey, I am trying to send a time and date to my database. The php code is: SET user_last_login = NOW() This sets it as: 2012-08-02 06:22:34 However this is 5 hours earlier than I want it. How can I change this so that it sets the timezone as GMT (Europe/London). I have tried changing the Global TimeZone in phpMyAdmin, and it says I need SUPER PRIVELIDGES to do so. I have tried date_default_timezone_set('Europe/London') and this also does not work. Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/ Share on other sites More sharing options...
Berre Posted August 2, 2012 Share Posted August 2, 2012 What happens if you change date_default_timezone_set() to some other place. Does the time change accordingly? Does "Europe/Paris" show one hour later that "Europe/London"? If so, maybe the server's time is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/#findComment-1366243 Share on other sites More sharing options...
Nothadoth Posted August 2, 2012 Author Share Posted August 2, 2012 I ran this in my header: date_default_timezone_set('Europe/London'); echo " " . date("m/d/y",time()); and it echo'd: 08/02/12 No time was acctually displayed. Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/#findComment-1366245 Share on other sites More sharing options...
Nothadoth Posted August 2, 2012 Author Share Posted August 2, 2012 I logged in and checked the database to see what NOW() had produced and it was still 5 hours behind. No change after the code I posted above. Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/#findComment-1366246 Share on other sites More sharing options...
Berre Posted August 2, 2012 Share Posted August 2, 2012 No time was acctually displayed. What do you mean? echo date("m/d/y",time()); This is specifically telling it to display only month, day and year in the first parameter ("m/d/y"). This however will include a 24 hour time at the end. echo date("m/d/y H:i:s",time()); What's the different times produced if you try different locations in date_default_timezone_set(); Does "Europe/Paris" output 1 hour later? And I don't think date_default_timezone_set() will affect MySQL's NOW(), only PHP's time(). I guess your server has the wrong settings (not set timezone correctly or wrong time). I also don't think date_default_timezone_set() will affect the timestamp itself. If you change it, time() will show the time number, but when you convert it with date() it will show different times based on timezone. The timestamp is universal. Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/#findComment-1366247 Share on other sites More sharing options...
Nothadoth Posted August 2, 2012 Author Share Posted August 2, 2012 Ok so I echo'd the code below and changed the date_default_timezone_set to Europe/London and it gave the correct time, and then changed it to Europe/Paris and it displayed a time 1 hour in front. So it seams that code is working. date("m/d/y H:i:s",time()); Now I need to get this date and time in to my database. Using NOW() still gives a time 5 hours behind. If i define the code above as variable $datetimestamp and then use the code below would that work? I would probably have to change the database column to varchar? SET user_last_login = '$datetimestamp' Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/#findComment-1366249 Share on other sites More sharing options...
Nothadoth Posted August 2, 2012 Author Share Posted August 2, 2012 I got it to work using what I said in my above post. Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/#findComment-1366254 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.