MySQL query to get the current date records wherein one of the columns displays current date


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('John1@gmail.com','John','2019-01-31 12:45:22');
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable706 values('Chris123@gmail.com','Chris','2019-07-22 10:05:02');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable706 values('12Robert@gmail.com','Robert','2019-06-22 11:25:22');
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable706 values('DavidM@gmail.com','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      |
+--------------------+----------+---------------------+
| John1@gmail.com    | John     | 2019-01-31 12:45:22 |
| Chris123@gmail.com | Chris    | 2019-07-22 10:05:02 |
| 12Robert@gmail.com | Robert   | 2019-06-22 11:25:22 |
| DavidM@gmail.com   | 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      |
+--------------------+----------+---------------------+
| Chris123@gmail.com | Chris    | 2019-07-22 10:05:02 |
| DavidM@gmail.com   | David    | 2019-07-22 00:00:02 |
+--------------------+----------+---------------------+
2 rows in set (0.00 sec)

Updated on: 21-Aug-2019

151 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements