- 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
Get two days data (today and yesterday) from a MySQL table with timestamp values
Let us first create a table −
mysql> create table DemoTable1495 -> ( -> ShippingDate bigint -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1495 values(1570127400); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1495 values(1570213800); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1495 values(1570645800); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1495 values(1570300200); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1495;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 1570127400 | | 1570213800 | | 1570645800 | | 1570300200 | +--------------+ 4 rows in set (0.00 sec)
The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-10-06 | +------------+ 1 row in set (0.00 sec)
Here is the query to get two days data from MySQL −
mysql> select * from DemoTable1495 -> where ShippingDate >=unix_timestamp(curdate() - interval 1 day) -> and -> ShippingDate < unix_timestamp(curdate() + interval 1 day);
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 1570213800 | | 1570300200 | +--------------+ 2 rows in set (0.00 sec)
Advertisements