Fetching rows updated at timestamp older than 1 day in MySQL?

For this,yYou can use from_unixtime() along with now().

Let us create a table with some data type −

Example

mysql> create table demo75
   -> (
   -> due_date int(11)
   -> );
Query OK, 0 rows affected, 1 warning (2.87

Insert some records into the table with the help of insert command −

Example

mysql> insert into demo75 values(unix_timestamp("2020-01-10"));
Query OK, 1 row affected (0.46

mysql> insert into demo75 values(unix_timestamp("2020-11-19"));
Query OK, 1 row affected (0.59

mysql> insert into demo75 values(unix_timestamp("2020-12-18"));
Query OK, 1 row affected (0.44

mysql> insert into demo75 values(unix_timestamp("2020-11-10"));
Query OK, 1 row affected (0.70

Display records from the table using select statement −

Example

mysql> select *from demo75;

This will produce the following output −

Output

<p>+------------+</p><p>| due_date   |</p><p>+------------+</p>| 1578594600 |
<p>| 1605724200 |</p>| 1608229800 |
<p>| 1604946600 |</p>+------------+
<p>4 rows in set (0.00 sec)</p>

Following is the query to fetch rows updated at a timestamp older than 1 day in MySQL −

Example

mysql> select * from demo75
   -> where from_unixtime(due_date) < now() - interval 1 day;

This will produce the following output −

Output

<p>+------------+</p>| due_date   |
<p>+------------+</p>| 1578594600 |
<p>| 1604946600 |</p><p>+------------+</p><p>2 rows in set (0.00 sec)</p>
Updated on: 2020-12-11T05:28:02+05:30

963 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements