- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements