Display Timestamp before the current date in MySQL


Let us first create a table −

mysql> create table DemoTable(
   ArrivalDate timestamp
);
Query OK, 0 rows affected (1.96 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2019-09-14 17:25:00');
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable values('2019-09-13 17:25:00');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('2016-09-01 17:20:10');
Query OK, 1 row affected (0.38 sec)
mysql> insert into DemoTable values('2019-09-11 12:00:00');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+---------------------+
| ArrivalDate         |
+---------------------+
| 2019-09-14 17:25:00 |
| 2019-09-13 17:25:00 |
| 2016-09-01 17:20:10 |
| 2019-09-11 12:00:00 |
+---------------------+
4 rows in set (0.04 sec)

Following is the query to display timestamp before the current date −

mysql> select *from DemoTable where ArrivalDate < now();

This will produce the following output −

+---------------------+
| ArrivalDate         |
+---------------------+
| 2019-09-13 17:25:00 |
| 2016-09-01 17:20:10 |
| 2019-09-11 12:00:00 |
+---------------------+
3 rows in set (0.07 sec)

Updated on: 27-Sep-2019

98 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements