
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to check how to get time difference
Let us first create a table −
mysql> create table DemoTable1570 -> ( -> ArrivalTime datetime -> ); Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1570 values('2019-10-15 5:10:00'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1570 values('2019-10-15 23:00:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1570 values('2019-10-15 23:10:00'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1570 values('2019-10-15 16:10:00'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1570;
This will produce the following output
+---------------------+ | ArrivalTime | +---------------------+ | 2019-10-15 05:10:00 | | 2019-10-15 23:00:00 | | 2019-10-15 23:10:00 | | 2019-10-15 16:10:00 | +---------------------+ 4 rows in set (0.00 sec)
The current date is as follows −
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-10-15 22:26:14 | +---------------------+ 1 row in set (0.00 sec)
Following is the query to get time difference −
mysql> select * from DemoTable1570 -> where ArrivalTime > now() - interval 5 hour;
This will produce the following output
+---------------------+ | ArrivalTime | +---------------------+ | 2019-10-15 23:00:00 | | 2019-10-15 23:10:00 | +---------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- How to measure actual MySQL query time?
- Get the time difference and convert it to hours in MySQL?
- How to get time difference between two timestamps in seconds?
- How to get the Average on MySQL time column?
- MySQL query to insert current date plus specific time?
- MySQL query to check if multiple rows exist?
- How to check the difference between plot generation time in base R?
- How to get the fourth highest value using MySQL query?
- How to get multiple rows in a single MySQL query?
- Get the time difference between values in different columns with MySQL
- MySQL Query to get count of unique values?
- How to calculate the difference between time in different MySQL columns?
- MySQL query to extract time in a format without seconds
- MySQL query to select rows one batch at a time
- How can I check how much time MySQL query, without printing it on the console, is taking?
Advertisements