I'm developing an app that meant to run only in Israel.
All of our tables contains times at Israeli time (Tel Aviv time).
because the SQL in GCP doesn't support default timezone and time zone convert I got stuck.
how can I convert times between time zones?
let me remind you that Israel has a light saving time change.
Now you have the ability to set the time zone in Cloud SQL. See https://cloud.google.com/sql/docs/mysql-flags. The limitation is that the time zone needs to be specified as offsets to UTC, such as '+10:00'. It does not support named time zones like 'Europe/Helsinki'.
Cloud SQL now supports named time zones. See a list here: https://cloud.google.com/sql/docs/mysql/flags#timezone-names
When using timezone names, automatic adjustment to daylight saving time is supported.
What is weird is that even though when explaining named time zones it gives the example Europe/London, in the actual list that's missing. The closest equivalent is Europe/Dublin, which is functionally the same although their summer time is considered "standard" so they switch to winter time.
THIS ANSWER IS OBSOLETE
On Google Cloud SQL you cannot currently set your own time zone. If you need to change the time zone on your instance, please get in touch with cloud-sql#google.com.
Related
I'm try to deal with the winter and summer time in a Google Cloud SQL instance. What I'm doing now is changing the flag default_time_zone in the configuration every time the time in my region changes. I need it to do it automatically. What I tried already:
1) Looking for a configuration for Time Zone Name to set "Europe/Paris" instead of "+01:00", but Google Cloud doesn't work with this (there's a request for developers of Google to do it but it's not done yet).
2) Changing with a script with "set global ##time_zone='Europe/Paris'" but it raises:
ERROR 1227 (42000): Access denied; you need (at least one of) the
SUPER privilege(s) for this operation
because GCP doesn't allow use super user on mySQL.
Any idea how to bear with this ?
Unfortunately, as per the documentation:
Automatic adjustment to daylight savings time is not supported; you
must update the default_time_zone flag manually to account for
daylight savings time.
So currently, the only approach is to wait for feedback from the Cloud SQL engineering team in the public Feature Request regarding the daylight saving time support. There's also another Feature Request open to allow changing this yourself in the MySQL time_zone table as per 2), which you might find useful to keep track of by starring it.
I am trying to find out how to take the TimeZone or TimeZoneInfo object in .NET and use it to convert all my dates in my MySQL database from UTC to the Local Users Correct Time Zone. I am building a Desktop App. I'm planing on using the built in Convert_TZ function, but the Information that i get back from those objects does not line up with the built in method.
I found this article (http://codeofmatt.com/2014/04/07/working-with-time-zone-names-in-net/) which puts the Time Zone Info object into a better format for display but it still does not match up.
I am very new to using the TimeZone object. If there is a better way to get the current Time Zone and is easier to use then I will try that.
MySQL uses IANA time zones. You can read about MySQL's time zone support here. You can read about the different types of time zones in the timezone tag wiki.
.NET on Windows works with Microsoft Windows time zones. This is done via the TimeZoneInfo object. The older TimeZone object is also in the .NET Framework, but should not be used anymore.
To work with IANA time zones instead of Windows time zones within .NET, you can use the Noda Time library. Using Noda Time, you can get the system's local IANA time zone like this:
string tz = DateTimeZoneProviders.Tzdb.GetSystemDefault().Id;
Note that .NET on Linux or macOS already uses IANA time zones with the TimeZoneInfo object, so Noda Time is optional.
If you already are using Windows time zones, you can convert them to IANA time zones, using the methods described here.
Also note that in a previous version of this answer, I advised against using MySQL's built-in time zone support on Windows because they had not been keeping the time zone data current. This was reported to the MySQL team here, and has been fixed. If you are running MySQL on Windows, you will find the latest time zone data files here.
I'm having hard time to decide on the right approach for data saving from different time zones:
I'm building an application that supposed to serve users from all over the world.
I have a table named Events which saves events the users inserted.
In this table there are Start_Time and End_Time columns of the event, which I some time need to run a select query according to does columns, and in relevant to user's current time.
I'm thinking about what the best approach for saving does times in the database. obviously I have some lack of knowledge in the time zones field.
For now i'm saving all the times as current UTC time stamp, and i'm not sure that its the right way to do so.
can anyone please provide some guidelines or documents about to right way to store it ?
hey according to my understanding you have a application that send request to this database on behalf of user, and user has its own date and time zone.
I would recommend to change your request time zone on application level to UTC. bring your application and database to same page and then after processing you can convert it back to local time zone.
what application language your are using?
I have a web server which will be serving people from around the world.
The time is a really important matter in my application, since a lot of queries are taking the time in consideration.
I need a way to store user's and server's time differences.
For example:
User login to server and send its current time.
Server's save the current time difference in mySql server
Every every time the server needs to use user's time in a query he knows how to calculate it since
it knows the difference..
What i really need is the server's ability to calculate user's time according to server's own time.
I've read about using UTC time but i didn't really understand how to implement it...
Let's say you are in the US and i am in the UK. If we both check the UTC time at the same time (with whatever code/method) we should see the same result. Check out the different ways of getting UTC timestamps in milliseconds. Then, in theory, if you sync everything by UTC time (including the server) you don't really need to be aware of timezone offsets because these offsets are only relevant if you consider the server time is based on its local timezone.
In MySQL you can get a unix timestamp with UNIX_TIMESTAMP(). As far as i know it has granularity to the second, not millisecond (so you will get the number of seconds since 1970). You can also check out UTC_TIME() and UTC_TIMESTAMP().
Could anyone help me with a sugesstion, how can I implement following stuff:
I have a system A where my sql server is installed.
But I want to have different timezone for my database in sql server not the system A timezone.
SQL Server has no concept of a time zone. It inherits the system time from Windows, and uses that in real time. For example, if you install SQL Server while the system is in one time zone, and you change the server to a different time zone, the next time you call GETDATE() it will reflect the new time zone, not the one that was in use at the time SQL Server was installed.
In this scenario I think you should just always store UTC data (e.g. using GETUTCDATE() instead of GETDATE(). Much easier to convert it later to your desired (or any!) time zone, e.g. .NET has all kinds of built-in functionality to handle this for you.
I would recommend to use this (EST in this example)
SYSDATETIMEOFFSET() AT TIME ZONE 'Eastern Standard Time'
This return precise time date with offset for any selected time zone.
This approach will not depend on server time zone.