
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to make MySQL's NOW() and CURDATE() functions use UTC?
To make MySQL’s NOW() and CURDATE() functions use UTC, you need to write my.cnf file. Write the below instruction in my.cnf −
[mysqld_safe] timezone = UTC
Firstly, reach the directory with the help of the following query −
mysql> select @@datadir;
The following is the output −
+---------------------------------------------+ | @@datadir | +---------------------------------------------+ | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ | +---------------------------------------------+ 1 row in set (0.00 sec)
Now reach the directory for which the link we got as the result of a query. The screenshot of my.cnf file on my Windows system −
Place option( [mysqld_safe] timezone = UTC ) under “mysqld”. You do not have to write on every page load. After placing it once in “my.cnf” file, you do not need to mention it again and again. It will work for every page load.
Call the below query for every page −
mysql> SET time_zone = ' + 0:00'; Query OK, 0 rows affected (0.00 sec)
But it’s not a good practice to call a query every time.
- Related Articles
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- CURDATE () vs NOW() in MySQL
- What is the difference between MySQL NOW() and CURDATE() function?
- How to use CONTAINS() with CURDATE in MySQL?
- MySQL's now() +1 day?
- How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?
- How to get computer's UTC offset in Python?
- How to get the previous day with MySQL CURDATE()?
- How to use MySQL Date functions with WHERE clause?
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- Can I write my own MySQL functions to use in MySQL queries?
- How to use now in timestamp in Android sqlite?
- Change the curdate() (current date) format in MySQL
- How to use DATETIME functions in Oracle?
- How to apply NOW() to timestamps field in MySQL Workbench?

Advertisements