Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/243009-insert-date-time-in-mysql/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.