Jump to content

Insert date time in mysql


teknospr

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.