mysql_query("SET time_zone = '+4:00'") or die("");
mysql_query("insert into `aa` set mytim = now()") or die("");
I expect this to insert time GMT +4 time in database but it does not do that. how can i do that? i have field of "timestamp" type and i want to insert FMT +4 time in it when updated.
Timestamps are saved internally as UTC (GMT +0). The only thing that changes is the select values depending on the time zone you set. Issuing a SET time_zone query before you insert is meaningless, SET time_zone is per connection and inserts don't need timezone. You can set the global timezone using SET GLOBAL time_zone. Personally, I always fetch the unix timestamp (using UNIX_TIMESTAMP()) and allow PHP native timezone aware functions to take care of it.
pytrin wrote:SET time_zone is per connection and inserts don't need timezone.
This really depends on where the value for insert is coming from. If it's coming from some internal function (like itsmani1 is using) - then you're right and connection timezone won't affect the insert. However if you pass the value literally in the query string then it would be converted to UTC according to the current connection timezone. And if you fail to set it properly, it won't be converted properly.
itsmani1 wrote:By going into to database see values in tables.
'Going into database' means connecting to it right? And it's where your per-connection (of the tool you use for checking) timezone kicks in. Thus timestamps are converted to requester's timezone.