
- 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
What would be output if we will try to extract time values by providing the date values only to MySQL EXTRACT() function?
When we try to extract hour value from a date, then EXTRACT() function will give the output 0 with a warning as shown in the below-given example −
mysql> Select EXTRACT(Hour from '2017-10-20'); +---------------------------------+ | EXTRACT(Hour from '2017-10-20') | +---------------------------------+ | 0 | +---------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> Show Warnings; +---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2017-10-20' | +---------+------+----------------------------------------------+ 1 row in set (0.00 sec)
Now, when we try to extract minute value from a date, then EXTRACT() function will give the value of century from date as the output with a warning as shown in the below-given example −
mysql> Select EXTRACT(Minute from '2017-10-20'); +-----------------------------------+ | EXTRACT(Minute from '2017-10-20') | +-----------------------------------+ | 20 | +-----------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> Show Warnings; +---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2017-10-20' | +---------+------+----------------------------------------------+ 1 row in set (0.00 sec)
Now, when we try to extract seconds value from a date, then EXTRACT() function will give the value of year as the output with a warning as shown in the below given example −
mysql> Select Extract(Second from '2017-10-20'); +-----------------------------------+ | Extract(Second from '2017-10-20') | +-----------------------------------+ | 17 | +-----------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> Show Warnings; +---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2017-10-20' | +---------+------+----------------------------------------------+ 1 row in set (0.00 sec)
We will get similar results on trying to get the time values(Hour, Minute & Seconds) from current date i.e. by using Curdate() at the place of date.
- Related Articles
- MySQL query to extract only the day instead of entire date
- What would be the output of MySQL SUM() function if a column having no values has been passed as its argument?
- How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
- What would be the effect on MySQL output if we have the combination of NULL and other values in the list of strings, provided as arguments in FIELD() function?
- How to extract date from string in MySQL?
- How can I use TIME_FORMAT() function to offload time/date values in MySQL?
- What is MySQL STRCMP() function and what would be the output of this function?
- MySQL extract year from date format?
- Extract values from HashMap in Java
- What kind of compound units can be used in MySQL EXTRACT() function?
- How can we extract the Year and Month from a date in MySQL?
- Extract Numeric Date Value from Date Format in MySQL?
- Extract tuples with specified common values in another column in MySQL?
- Extract unique values from an array - JavaScript
- Extract Unique dictionary values in Python Program

Advertisements