4

I am working on shopping cart, which stores DateTime in orders table when order is placed.

one of the row in order table shows date time 2015-07-24 02:34:45

When I display same on PHP page it displays 2015-07-24 01:43:33

It is happening with all entries in orders table. I am considering just one here, date displays correctly but time is not displaying properly

Default time zone is America/New_York

I am just selecting rows from order table and displaying on a PHP page.

8
  • How are you displaying the date time on your page? How is the date stored on your database? Commented Jul 29, 2015 at 7:15
  • what framework / function are you using for displaying and saving date? Commented Jul 29, 2015 at 7:16
  • MySql and PHP have separate configurations for timezones. So NOW() in MySql doesn't have to use the same timezone as set in PHP Commented Jul 29, 2015 at 7:16
  • Please specify the framework which you are using Commented Jul 29, 2015 at 7:18
  • Best to always save dates / times as UTC and adjust as needed when outputting. Makes life much easier and consistent. Commented Jul 29, 2015 at 7:22

2 Answers 2

2

Setting GLOBAL value by command line will be reset if you restart your MySql. Instead set this in your my.cnf like

default-time-zone = "America/New_York"

Don't forget to restart your MySql after setting the option

Sign up to request clarification or add additional context in comments.

Comments

2

Mysql timezone != PHP timezone, you need set both separately. If your php.ini have America/New_York you need execute this mysql query:

SET GLOBAL time_zone = 'America/New_York';

1 Comment

it will be apply to current database or all database ?, i have number of other databse too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.