Reputation: 8597
I need help understand how mysql can determine what the timezone is when I use the function now() (in mysql) when I insert into mysql database. The datetime format is YYYY-MM-DD 00:00:00. How do you get the user to get the right time at their location?
Does this question make sense?
Thank you for your time!
Upvotes: 1
Views: 1086
Reputation: 47321
now()
is always refer to the server time from its timezone.
If you have both server and user timezone,
it can be done via function convert_tz
,
such as
set @user_time_zone:='+02:00';
set @server_time_zone:='+08:00';
-- server timezone always come first
-- as now() is from server time
SELECT CONVERT_TZ(now(),@server_time_zone, @user_time_zone);
Upvotes: 3
Reputation: 5058
The system timezone is controlled by system_time_zone variable. you can view the current system time zone using the following in the mysql prompt
SELECT @@system_time_zone;
The system time zone can be changed using --timezone=timezone_name in the mysql server option
Upvotes: 1
Reputation: 5463
the now() function return system time determine your server's time and location! mysql can not do this for u, this is your program's job!!
Upvotes: 1
Reputation: 31098
Your datetime format YYYY-MM-DD 00:00:00
has no timezone information, so it's irrelevant which timezone the user is in.
NOW()
uses the system's time.
Upvotes: 1