Date Arithmetic Operations in MySQL

seetha
Updated on 28-Jan-2020 11:01:22

185 Views

When we try to do such kind of operations with date values stored in the table then MySQL is assuming the date values as the number and perform the arithmetic.Suppose we have a table named ‘example’ having a date value in ‘orderdate’ column then following arithmetic operation will clarify the above −mysql> select * from example; +------------+ | orderdate  | +------------+ | 2017-05-25 | +------------+ 1 row in set (0.00 sec) mysql> select orderdate+10 from example; +--------------+ | orderdate+10 | +--------------+ |     20170535 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate*10 from example; ... Read More

Check MySQL Tables by Column Name

Manikanth Mani
Updated on 28-Jan-2020 10:58:20

114 Views

The following statement shows the list of two tables having a column ‘email’ in Sample database −mysql> SELECT DISTINCT TABLE_NAME     -> FROM INFORMATION_SCHEMA.COLUMNS     -> WHERE COLUMN_NAME IN('EMAIL')     -> AND TABLE_SCHEMA = 'SAMPLE'; +---------------+ | TABLE_NAME    | +---------------+ | employee      | | new_student   | +---------------+ 2 rows in set (0.04 sec)

Difference Between MySQL NOW() and CURDATE() Function

Prabhas
Updated on 28-Jan-2020 10:57:02

2K+ Views

As the name suggests CURDATE() function will return the current date. In simple words, we can say that it would return only the date not time.mysql> select CURDATE(); +------------+ | CURDATE()  | +------------+ | 2017-10-28 | +------------+ 1 row in set (0.00 sec)In contrast, NOW() function will return current date and time.mysql> Select NOW(); +---------------------+ | NOW()               | +---------------------+ | 2017-10-28 09:10:16 | +---------------------+ 1 row in set (0.00 sec)

Check Size of All MySQL Databases

Ankith Reddy
Updated on 28-Jan-2020 10:56:05

131 Views

We can check the size of all MySQL databases with the help of the following statementmysql> SELECT table_schema "Database", -> SUM(data_length + index_length)/1024/1024 "Size in MB" -> FROM information_schema.TABLES GROUP BY table_schema; +--------------------+----------------+ | Database           | Size in MB     | +--------------------+----------------+ | gaurav             | 1.04785156     | | information_schema | 0.00878906     | | mysql              | 0.68551350     | | performance_schema | 0.00000000     | | sample             | 0.04687500     | | tutorial           | 0.03125000     | +--------------------+----------------+ 6 rows in set, 1 warning (0.33 sec)

How E-Stores Are Winning Hearts in India

Samual Sam
Updated on 28-Jan-2020 10:55:52

130 Views

It is raining discounts and offers on all shopping websites. Online shopping is an activity wherein customers use Internet to order a product or a service at any moment of time and the product is delivered at their doorsteps.Online stores have made shopping easy with the usage of mobile devices, tablets, or laptops that aid most of the online shopping apps. You can enjoy all the products and services just by a click from the comfort of your drawing room or while you are on the go. Online shopping is winning the hearts of shopaholics all over India.Why would Anyone ... Read More

Check Size of Tables in MySQL Database

Monica Mona
Updated on 28-Jan-2020 10:55:04

357 Views

As we have checked the size of the MySQL database, similarly we can also check the size of tables in a particular database. It can be done as follows −mysql> SELECT     -> table_name AS "Table",     -> round(((data_length + index_length) / 1024 / 1024), 2) as SIZE     -> FROM information_schema.TABLES     -> WHERE table_schema = "SAMPLE"     -> ORDER BY SIZE; +-------------+-------+ | Table       | SIZE  | +-------------+-------+ | employee    | 0.02  | | student     | 0.02  | | new_student | 0.02  | +-------------+-------+ 3 rows in set (0.00 sec)Here this output gives the size of three tables in the Sample database.

MySQL INTERVAL with CURDATE Function

varun
Updated on 28-Jan-2020 10:52:40

128 Views

As we know that CURDATE() only returns the date unit so it would be ambiguous to use INTERVAL of time unit with CURDATE(). MySQL always represents current date with ‘00:00:00’ time hence when we use INTERVAL of time unit with CURDATE() then such kind of time arithmetic would take this time into consideration. Following examples will clarify it −mysql> Select CURDATE() + INTERVAL 0 hour; +-----------------------------+ | curdate() + Interval 0 hour | +-----------------------------+ | 2017-10-28 00:00:00         | +-----------------------------+ 1 row in set (0.00 sec) mysql> select CURDATE() + INTERVAL 1 hour; +-----------------------------+ | curdate() ... Read More

Why Output is Zero When Converting Date to TIMESTAMP

mkotla
Updated on 28-Jan-2020 10:50:53

360 Views

As we know that with the help of MySQL UNIX_TIMESTAMP function, we can produce the number of seconds from given date/DateTime. But when we try to convert a date like ‘1965-05-15’ it would give 0(Zero) as output because the range of TIMESTAMP is between ‘1970-01-01 00:00:01’ to ‘2038-01-19 08:44:07’. Hence, the date values beyond TIMESTAMP range cannot be converted and will return 0 as output always.Examples are given below −mysql> Select UNIX_TIMESTAMP ('1965-05-15'); +----------------------------------------------+ | unix_timestamp('1965-05-15 05:04:30')        | +----------------------------------------------+ |                                   ... Read More

How Google Earth VR Makes Virtual Travel a Reality

Samual Sam
Updated on 28-Jan-2020 10:48:04

278 Views

How it would feel like if you were to stand on the top of Burj Khalifa or to view the beautiful Taj Mahal from a bit closer or to fly over the Great Wall of China, live just by sitting on your couch? Well, a virtual reality (VR) based application of Google can do that for you.This technology sounds much similar to some earlier applications of Google where one can make a virtual tour just by sitting at home. Yes but they cannot let you see the on road trees and other objects with a clarity that Google VR does ... Read More

Convert Seconds to TIMESTAMP in MySQL

Sravani S
Updated on 28-Jan-2020 10:44:24

1K+ Views

It is exactly reverse of UNIX_TIMESTAMP() and can be done with the help of FROM_UNIXTIME() function. For example, 11576070 seconds would be TIMESTAMP ‘1970-05-15 05:04:30’.mysql> Select FROM_UNIXTIME(11576070); +--------------------------------+ | FROM_UNIXTIME(11576070)        | +--------------------------------+ |      1970-05-15 05:04:30       | +--------------------------------+ 1 row in set (0.00 sec)

Advertisements