php - How to deal with time zone in MySQL? -


I have a script that works like "Google Analytics" to basically display visitor statistics for a user .

I want to generate a report in that user's time zone.

So far I have written a code with it:

  SET time_zone = timezone;   

This determines the time zone according to each MySQL connection. If a user retrieves data with the timestamp , the timestamp changes to the time zone of the connection. I am accumulating UTC in the timestamp.

So everything seems to work. But some people are saying that this is a wrong view. Because many users can not connect to the database with different time_zone settings.

But they say:

The per-connection time zone that each customer connects, has its own time zone setting, according to the time zone_zone of the session it happens. Initially, the session variable takes the value of it from the global time_zone variable, but the client can change its time zone with this statement

Although they urge you to do anything with time zone Should not in MySQL at all. You should do this in your (for example) PHP code. A similar question with this answer.

But how can I do this in PHP code? I mean, I know how to convert time with a time zone in PHP, but it is not that I am retaining a line.

I am retrieving thousands of rows and they have timestamp fields in the date:

  SELECT ... log from WHERE user_id =: user_id And timestamp> = CURDATE () group by DATE (timestamp)   

It is very important that the MySQL is using timestamp index because I have millions of what index works, however I use a function on timestamp GROUP BY DATE (timestamp) I am doing? If not, how can I complete it?

So how should I do all this? I would be truly grateful for some advice.

Now the user changes his timestamp into his tz and uses the timestamp (* user) & Gt; = CURDATE (* User). I think

  convert timestamp (user) to timestamp (server)   

and use

  timestamp (* Server) & gt; = CURDATE (* server)   

example

  date = (5,6,7)   

(my Tz) Dates-2 = (3,4,5) (check directly with this array directly) bigThan3 result = (4,5) Second way (hinders change from TS server) ) Big Tata 3 - & gt; Large (3 + 2) 5 (check barrier with server array) Dates = (5,6,7) Results = (6,7) Result can be changed (4,5)

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -