To achieve this, following is the syntax wherein we have used DATE(NOW()) −
select *from yourTableName where DATE(yourColumnName)=DATE(NOW());
Let us first create a table −
mysql> create table DemoTable706 ( UserId varchar(100), UserName varchar(100), UserSignupDate datetime ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable706 values('[email protected]','John','2019-01-31 12:45:22'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable706 values('[email protected]','Chris','2019-07-22 10:05:02'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable706 values('[email protected]','Robert','2019-06-22 11:25:22'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable706 values('[email protected]','David','2019-07-22 00:00:02'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable706;
This will produce the following output -
+--------------------+----------+---------------------+ | UserId | UserName | UserSignupDate | +--------------------+----------+---------------------+ | [email protected] | John | 2019-01-31 12:45:22 | | [email protected] | Chris | 2019-07-22 10:05:02 | | [email protected] | Robert | 2019-06-22 11:25:22 | | [email protected] | David | 2019-07-22 00:00:02 | +--------------------+----------+---------------------+ 4 rows in set (0.00 sec)
Following is the query to get records wherein one of the columns displays current date −
mysql> select *from DemoTable706 where DATE(UserSignupDate)=DATE(NOW());
This will produce the following output -
+--------------------+----------+---------------------+ | UserId | UserName | UserSignupDate | +--------------------+----------+---------------------+ | [email protected] | Chris | 2019-07-22 10:05:02 | | [email protected] | David | 2019-07-22 00:00:02 | +--------------------+----------+---------------------+ 2 rows in set (0.00 sec)