Definition of MariaDB Timezone Function
MariaDB provides a time zone variable to maintain the track of several time zone settings. Basically, time_zone is a system variable and it is a primary way to set the time zone. We can use different formats to set the timezone of the MariaDB server, normally by default the value of the time zone is SYSTEM and it is used to indicate the system time zone by using the system_time_zone system variable. Some we can also use Coordinated Universal Time zone. If we loaded the time zone table in the mysql database then we can have permission to access different time zones such as Africa, America or Europe, etc.
set time_zone = ‘value’’
In the above syntax, we use the set keyword with time_zone system variable to set the time zone of a specified country or area, which is dependent on user requirement.
How does Timezone function work in MariaDB?
Time zone uses a different parameter during the setting of the time_zone system variable, so let’s see how it works. Normally there are two different time zone settings we need to set within the MariaDB server such as global server time zone and time zone for the current session.
Global Server Time Zone
The global server time zone we can change by using two different ways such as by using settings in which we can set default time zone option and the alternate option is that by using the command line. We are also able to change the global server time zone by using dynamic settings but the user account has the permission of super privilege.
Session Time Zone
When a session is connecting to the server it also has its own local time zone we call session time zone. Basically, the session time zone is generated from the global value of the time_zone system variable. The session time zone we can change by using the dynamic setting of the time_zone system variable.
System Time Zone
The system time zone value we can determine when we start the server and it sets the value of system_time_zone system variable. Normally the system time zone fetches current time from the operating system. We can change the system time zone by using different ways as follows.
First way is that when we start the server with mysqlld_safe at that time we can set the system time zone with time zone value and another way is by using the command line option. If you are using the UNIX operating system then you can set the system time zone by setting the environment variable.
Time zone Effects on Functions
When we set a time zone variable at that time some functions are affected as follows.
Now function is used to current date and time as a value in YYYY-MM-DD format. The return value is shown in the current time zone. The precision is an optional part of the now function and it is used to determine in microseconds.
With the help of now function we can fetch the current date and time of the system. The final output of the above query we illustrate by using the following snapshot
Select now() +0;
The final output of the above query we illustrate by using the following snapshot.
Let’s see some examples of now function with precision as follows.
In the above example, we use a precision value that is the current timestamp value as shown in the above statement. The final output of the above query we illustrate by using the following snapshot.
SYSDATE is also used to return data and time in YYYY-MM-DD format with time format. Precision part of the SYSDATE function is optional. Basic difference between NOW() and SYSDATE() is that SYSDATE() is used to return the time at which time is executed and NOW() function is used to return constant time at which time the statement began to execute.
select now(), sleep(4), now();
In the above example, we use now and sleep function to see the difference between now and sysdate function. The final output of the above query we illustrate by using the following snapshot.
SELECT SYSDATE(), SLEEP(4), SYSDATE();
In the above example, we use the sysdate function with a sleep parameter as shown. The final output of the above query we illustrate by using the following snapshot.
It also returns the current date in format YYYY-MM-DD and it depends on whether the function is used a string or a number.
This function is used to returns current time in HHMMSS or HH:MM:SS format and it also depends on whether function is used a string or number.
If we call this function without an argument then it returns a UNIX timestamp as an unsigned integer. if we use uinix_timestamp() it returns a data argument with UTC value. Maximum value of Timestamp is 2147483647 equivalent to 2038-01-19 05:14:07.
In the above statement, we use UNIX_TIMESTAMP function to see the time stamp value without any argument. The final output of the above query we illustrate by using the following snapshot.
Some functions are not affected listed as follows.
SHOW GLOBAL VARIABLES LIKE 'time_zone';
Suppose we need to see the global of the current server at that time we can use the above statement. In this statement we use the show global variable command with LIKE clause and time_zone is system variable. The final output of the above query we illustrate by using the following snapshot.
SET GLOBAL time_zone =”Africa/Johannesburg”;
In the above example, we use a set global keyword with a system variable time_zone as shown in the above statement. Suppose the user needs to set a global time_zone as per requirement then the user can use the above statement. In this example ‘Africa/Johannesburg’ is we consider the value we can change that value. The final output of the above query we illustrate by using the following snapshot.
We hope from this article you have understood about the MariaDB time_zone. From this article we have learned the basic syntax of time_zone and as well as we also see different examples of time_zone. From this article, we learned how and when we use MariaDB time_zone.
This is a guide to MariaDB Timezone. Here we discuss the Definition, How Timezone function works in MariaDB? along with the examples. You may also have a look at the following articles to learn more –