- MySQL Basics
- MySQL - Home
- MySQL - Introduction
- MySQL - Features
- MySQL - Versions
- MySQL - Variables
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Node.js Syntax
- MySQL - Java Syntax
- MySQL - Python Syntax
- MySQL - Connection
- MySQL - Workbench
- MySQL Databases
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Show Database
- MySQL - Copy Database
- MySQL - Database Export
- MySQL - Database Import
- MySQL - Database Info
- MySQL Users
- MySQL - Create Users
- MySQL - Drop Users
- MySQL - Show Users
- MySQL - Change Password
- MySQL - Grant Privileges
- MySQL - Show Privileges
- MySQL - Revoke Privileges
- MySQL - Lock User Account
- MySQL - Unlock User Account
- MySQL Tables
- MySQL - Create Tables
- MySQL - Show Tables
- MySQL - Alter Tables
- MySQL - Rename Tables
- MySQL - Clone Tables
- MySQL - Truncate Tables
- MySQL - Temporary Tables
- MySQL - Repair Tables
- MySQL - Describe Tables
- MySQL - Add/Delete Columns
- MySQL - Show Columns
- MySQL - Rename Columns
- MySQL - Table Locking
- MySQL - Drop Tables
- MySQL - Derived Tables
- MySQL Queries
- MySQL - Queries
- MySQL - Constraints
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Replace Query
- MySQL - Insert Ignore
- MySQL - Insert on Duplicate Key Update
- MySQL - Insert Into Select
- MySQL Indexes
- MySQL - Indexes
- MySQL - Create Index
- MySQL - Drop Index
- MySQL - Show Indexes
- MySQL - Unique Index
- MySQL - Clustered Index
- MySQL - Non-Clustered Index
- MySQL Operators and Clauses
- MySQL - Where Clause
- MySQL - Limit Clause
- MySQL - Distinct Clause
- MySQL - Order By Clause
- MySQL - Group By Clause
- MySQL - Having Clause
- MySQL - AND Operator
- MySQL - OR Operator
- MySQL - Like Operator
- MySQL - IN Operator
- MySQL - ANY Operator
- MySQL - EXISTS Operator
- MySQL - NOT Operator
- MySQL - NOT EQUAL Operator
- MySQL - IS NULL Operator
- MySQL - IS NOT NULL Operator
- MySQL - Between Operator
- MySQL - UNION Operator
- MySQL - UNION vs UNION ALL
- MySQL - MINUS Operator
- MySQL - INTERSECT Operator
- MySQL - INTERVAL Operator
- MySQL Joins
- MySQL - Using Joins
- MySQL - Inner Join
- MySQL - Left Join
- MySQL - Right Join
- MySQL - Cross Join
- MySQL - Full Join
- MySQL - Self Join
- MySQL - Delete Join
- MySQL - Update Join
- MySQL - Union vs Join
- MySQL Keys
- MySQL - Unique Key
- MySQL - Primary Key
- MySQL - Foreign Key
- MySQL - Composite Key
- MySQL - Alternate Key
- MySQL Triggers
- MySQL - Triggers
- MySQL - Create Trigger
- MySQL - Show Trigger
- MySQL - Drop Trigger
- MySQL - Before Insert Trigger
- MySQL - After Insert Trigger
- MySQL - Before Update Trigger
- MySQL - After Update Trigger
- MySQL - Before Delete Trigger
- MySQL - After Delete Trigger
- MySQL Data Types
- MySQL - Data Types
- MySQL - VARCHAR
- MySQL - BOOLEAN
- MySQL - ENUM
- MySQL - DECIMAL
- MySQL - INT
- MySQL - FLOAT
- MySQL - BIT
- MySQL - TINYINT
- MySQL - BLOB
- MySQL - SET
- MySQL Regular Expressions
- MySQL - Regular Expressions
- MySQL - RLIKE Operator
- MySQL - NOT LIKE Operator
- MySQL - NOT REGEXP Operator
- MySQL - regexp_instr() Function
- MySQL - regexp_like() Function
- MySQL - regexp_replace() Function
- MySQL - regexp_substr() Function
- MySQL Fulltext Search
- MySQL - Fulltext Search
- MySQL - Natural Language Fulltext Search
- MySQL - Boolean Fulltext Search
- MySQL - Query Expansion Fulltext Search
- MySQL - ngram Fulltext Parser
- MySQL Functions & Operators
- MySQL - Date and Time Functions
- MySQL - Arithmetic Operators
- MySQL - Numeric Functions
- MySQL - String Functions
- MySQL - Aggregate Functions
- MySQL Misc Concepts
- MySQL - NULL Values
- MySQL - Transactions
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - SubQuery
- MySQL - Comments
- MySQL - Check Constraints
- MySQL - Storage Engines
- MySQL - Export Table into CSV File
- MySQL - Import CSV File into Database
- MySQL - UUID
- MySQL - Common Table Expressions
- MySQL - On Delete Cascade
- MySQL - Upsert
- MySQL - Horizontal Partitioning
- MySQL - Vertical Partitioning
- MySQL - Cursor
- MySQL - Stored Functions
- MySQL - Signal
- MySQL - Resignal
- MySQL - Character Set
- MySQL - Collation
- MySQL - Wildcards
- MySQL - Alias
- MySQL - ROLLUP
- MySQL - Today Date
- MySQL - Literals
- MySQL - Stored Procedure
- MySQL - Explain
- MySQL - JSON
- MySQL - Standard Deviation
- MySQL - Find Duplicate Records
- MySQL - Delete Duplicate Records
- MySQL - Select Random Records
- MySQL - Show Processlist
- MySQL - Change Column Type
- MySQL - Reset Auto-Increment
- MySQL - Coalesce() Function
MySQL - UTC_TIME() Function
The MySQL UTC_TIME() function returns the current Coordinated Universal Time (UTC) as a time value. The resultant value is a string or a numerical value based on the context and, the time returned will be in the 'hh:mm:ss' or hhmmss format.
This function does not accept any arguments and just returns the current time. But we can still pass an optional argument to specify the number of digits to be displayed in the fractional part of seconds.
Syntax
Following is the syntax of MySQL UTC_TIME() function −
UTC_TIME();
Parameters
This method does not accept any parameters.
Return value
This function returns the current UTC (Coordinated Universal Time) time as a TIME value in the format 'HH:MM:SS'.
Example
In the following example, we are using the MySQL UTC_TIME() function to fetch the current UTC time −
SELECT UTC_TIME() As Result;
Output
This will produce the following result −
Result |
---|
10:03:47 |
Example
We can also use UTC_TIME instead of UTC_TIME() to retrieve the current UTC time −
SELECT UTC_TIME As Result;
Output
Following is the output −
Result |
---|
10:03:47 |
Example
Here, we are adding seconds to the UTC current time as shown below in the below query −
SELECT UTC_TIME()+12 As Result;
Output
Output of the above code is as follows −
Result |
---|
100359 |
Example
We can also subtract the desired number of seconds from the current time using this function −
SELECT UTC_TIME()-300 As Result;
Output
We get the output as shown below −
Result |
---|
100047 |
Example
This function accepts an optional argument i.e. fsp, using this we can specify the number of digits we need after the fraction for seconds −
SELECT UTC_TIME(5) As Result;
Output
The result obtained is as shown below −
Result |
---|
10:03:47.24164 |
In this example, we have created a table named SALES using the following CREATE TABLE query −
CREATE TABLE SALES( NAME varchar(255), PRODUCT varchar(255), DISPATCH_DATE date, DISPATCH_TIME time, LOCATION varchar(255) );
Now, insert the following records into the SALES table using the INSERT statement −
INSERT INTO SALES VALUES ('Aadhya', 'Key-Board', DATE('2019-05-04'), TIME('18:00:00'), 'Kerala'), ('Varun', 'Earphones', DATE('2019-06-26'), TIME('19:00:00'), 'Mumbai'), ('Vratha', 'Mouse', DATE('2019-12-07'), TIME('20:00:00'),'Vijayawada'), ('Rahul', 'Mobile', DATE('2018-03-21'), TIME('21:00:00'), 'Chennai'), ('Maaya', 'Headset', DATE('2018-12-30'), TIME('22:00:00'), 'Goa');
Execute the below query to fetch all the inserted records in the above-created table −
Select * From SALES;
Following is the ORDERS table −
NAME | PRODUCT | DISPATCH_DATE | DISPATCH_TIME | LOCATION |
---|---|---|---|---|
Aadhya | Key-Board | 2019-05-04 | 18:00:00 | Kerala |
Varun | Earphones | 2019-06-26 | 19:00:00 | Mumbai |
Vratha | Mouse | 2019-12-07 | 20:00:00 | Vijayawada |
Rahul | Mobile | 2018-03-21 | 21:00:00 | Chennai |
Maaya | Headset | 2018-12-30 | 22:00:00 | Goa |
The below query retrieves the time difference between "DISPATCH_TIME" and "UTC_TIME" columns from the "SALES" table −
SELECT NAME, DISPATCH_TIME, TIMEDIFF(DISPATCH_TIME, UTC_TIME) As Result FROM SALES;
Output
The output is displayed as follows −
CUST_NAME | DISPATCH_TIME | Result |
---|---|---|
Aadhya | 18:00:00 | 07:29:33 |
Varun | 19:00:00 | 08:29:33 |
Vratha | 20:00:00 | 09:29:33 |
Rahul | 21:00:00 | 10:29:33 |
Maaya | 22:00:00 | 11:29:33 |