mysql/php timezone issues

Go To StackoverFlow.com

1

I'm trying to use a timestamp for mysql entries, however it's showing up as behind 20 hours.

When I type the following into mysql command line the correct time is displayed (it's currently 8:15 PM Eastern)

SELECT NOW();

When I submit something into my database using the following, everything is correct except the time is being displayed as 12:15 am.

date('m/d/Y,h:i:a');

The column in my table is varchar(20) if that matters.

I also tried to make sure it's set to eastern timezone by using but got an error saying incorrect timezone.

SET time_zone = 'America/New_York'; 

Does anyone have a clue why I'm off by 20 hours in my databse entries but when I use mysql command line to look up the time it's displayed correctly?

2012-04-05 00:18
by user1104854


2

I'm assuming this is a PHP timezone issue. You should check what Timezone you have set in your PHP ini file.

[Date]
; Defines the default timezone used by the date functions
date.timezone = America/New_York

You can also set the timezone in your script:

ini_set('date.timezone', 'America/New_York');

Seems like you were trying to change the Timezone in MySQL. You should also check your timezone setting MySQL, just to make sure.

2012-04-05 00:27
by Gohn67
Where exactly in my script do I set this? I use a variable $timestamp = date('m/d/Y,h:i:a'); and then enter that variable. Would I set it before that variable - user1104854 2012-04-05 00:34
Yeah just do the ini_set at the beginning of the script - Gohn67 2012-04-05 00:37
To test, just print out the date to see if it is in the correct timezone - Gohn67 2012-04-05 00:37
You were correct, sir! Thanks - user1104854 2012-04-05 00:41
Ads