For this, you can use DATEDIFF(). Let us first create a table −
mysql> create table DemoTable -> ( -> ShippingDate datetime -> ); Query OK, 0 rows affected (0.90 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-07-01'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('2019-07-02'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-07-03'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('2019-07-04'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+---------------------+ | ShippingDate | +---------------------+ | 2019-07-01 00:00:00 | | 2019-07-02 00:00:00 | | 2019-07-03 00:00:00 | | 2019-07-04 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Following is the query to check if datetime equals tomorrows date in MySQL or not −
mysql> select *from DemoTable -> WHERE DATEDIFF(ShippingDate, DATE_ADD(CURDATE(), INTERVAL 1 DAY)) = 0;
This will produce the following output displaying tomorrows date 2019-07-02 was one of the dates in the table −
Output
+---------------------+ | ShippingDate | +---------------------+ | 2019-07-02 00:00:00 | +---------------------+ 1 row in set (0.08 sec)