Compare timestamp with date only

193 Views

Compare timestamp with date only

SQL | Compare timestamp with date only

Timestamp holds Date and Time both with 19 characters. To filter table record with date only parameter can be achieved by SQL DATE() function.

Consider the Employee table having the following records −

+----+----------+----------+----------------------+
| ID | NAME     | SALARY   | CREATED_DATE         |
+----+----------+----------+----------------------+
|  1 | Kamal    |  3000.00 |  2020-05-05 18:35:11 |
|  2 | Roshan   |  3000.00 |  2020-05-06 09:50:01 |
|  3 | Shyam    |  2000.00 |  2020-05-05 10:30:20 |
|  4 | Sagar    |  6500.00 |  2020-05-07 09:40:10 |
|  5 | Komal    |  8500.00 |  2020-05-05 11:35:25 |
+----+----------+----------+----------------------+

The following SQL query will select all the record having CREATED_DATE is "2020-05-05" 

 SELECT * 
FROM Employee 
WHERE DATE(CREATED_DATE) = "2020-05-05"

Above query generate the following output:-

+----+----------+----------+----------------------+
| ID | NAME     | SALARY   | CREATED_DATE         |
+----+----------+----------+----------------------+
|  1 | Kamal    |  3000.00 |  2020-05-05 18:35:11 |
|  3 | Shyam    |  2000.00 |  2020-05-05 10:30:20 |
|  5 | Komal    |  8500.00 |  2020-05-05 11:35:25 |
+----+----------+----------+----------------------+

 

Tags:-
SQL
MySQL