teknospr Posted July 27, 2011 Share Posted July 27, 2011 Good day: I'm trying to insert the local date, time at the moment of an entry in mysql. I have changed the date timezone and when I echo the date time to view it is on local time, however, it inserts the GMT time on mysql using the NOW()) function. I have that in mysql column setup as date. My time zone is America/Puerto_Rico or GMT -4. Thanks in advance for the help. Quote Link to comment https://forums.phpfreaks.com/topic/243009-insert-date-time-in-mysql/ Share on other sites More sharing options...
xyph Posted July 27, 2011 Share Posted July 27, 2011 MySQL prefers to have a global timezone set for the entire server. This can be an issue for shared hosting environments. Instead of NOW(), use PHP to generate the datetime entry. Use date_default_timezone_set() and date( 'Y-m-d H:i:s' ) If you must use NOW(), you can set a timezone in MySQL on a per-session basis. Call the query SET time_zone = timezone; right after you connect to MySQL in your script. Quote Link to comment https://forums.phpfreaks.com/topic/243009-insert-date-time-in-mysql/#findComment-1248133 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.