
- 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 can we convert TIME and DATETIME values to numeric form in MySQL?
Conversion of TIME(N) and DATETIME(N) values to numeric form can be done by adding 0(+0) to them. Followings are the rules for such kind of conversion −
Converted to INTEGER
The TIME(N) and DATETIME(N) values will be converted to an integer when N is 0.
For example, the values of CURTIME() and NOW() can be converted to integer values as follows −
mysql> SELECT CURTIME(), CURTIME()+0; +-----------+-------------------+ | CURTIME() | CURTIME()+0 | +-----------+-------------------+ | 19:42:54 | 194254 | +-----------+-------------------+ 1 row in set (0.04 sec) mysql> SELECT NOW(), NOW()+0; +-------------------------+----------------------------------+ | NOW() | NOW()+0 | +-------------------------+----------------------------------+ | 2017-10-27 19:43:43 | 20171027194343 | +-------------------------+----------------------------------+ 1 row in set (0.00 sec)
Converted to DECIMAL
The TIME(N) and DATETIME(N) values will be converted to an integer when N is greater than 0.
For example, the values of CURTIME() and NOW() can be converted to decimal values as follows −
mysql> SELECT CURTIME(), CURTIME(3)+0; +-----------+-------------------+ | CURTIME() | CURTIME()+0 | +-----------+-------------------+ | 19:47:40 | 194740.575 | +-----------+-------------------+ 1 row in set (0.04 sec) mysql> SELECT NOW(), NOW(3)+0; +-------------------------+----------------------------------+ | NOW() | NOW()+0 | +-------------------------+----------------------------------+ | 2017-10-27 19:48:45 | 20171027194845.589 | +-------------------------+----------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to convert JS date time to MySQL datetime?
- How can we enter numeric values as Hexadecimal (HEX) number in MySQL statement?
- How can we display MySQL bit values in printable form?
- How to convert JavaScript datetime to MySQL datetime?
- How can we calculate the difference between two time values in MySQL?
- How to convert timestamp to datetime in MySQL?
- How to part DATE and TIME from DATETIME in MySQL?
- How to convert a MySQL TIME value to days and hours form?
- Convert INT to DATETIME in MySQL?
- How to convert DateTime to a number in MySQL?
- How to use MySQL FROM_UNIXTIME() function to return datetime value in numeric format?
- How to convert MySQL datetime to Unix timestamp?
- How can we insert current date and time automatically on inserting values in other columns in MySQL?
- Convert from varchar to datetime and compare in MySQL?
- How to convert char field to datetime field in MySQL?

Advertisements