Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to query Datetime object by date?

i want to query a table according to a particular date, but the problem is the datatype of that field is datetime

select  * from  Supplier  where modified_Date='2011-05-07 12:52:16.830' 

this query is returning result

but

 select  * from  Supplier  where modified_Date='2011-05-07' 

there is no result

like image 677
Nighil Avatar asked May 23 '11 09:05

Nighil


People also ask

How do I select a date from a timestamp in SQL?

In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column. (In our example, we use a column of the timestamp data type.)

How can I get date between two dates in SQL?

How do I count days between two dates in SQL Server? To find the difference between dates, use the DATEDIFF(datepart, startdate, enddate) function. The datepart argument defines the part of the date/datetime in which you'd like to express the difference. Its value can be year , quarter , month , day , minute , etc.


1 Answers

SQL Server 2008 has a DATE data type. You can cast your DATETIME to DATE and perform the comparison.

SELECT *
FROM   Supplier
WHERE  CAST(Modified_Date AS DATE) = '2011-05-07'

Reference: DateTime TransactSQL

like image 181
Lieven Keersmaekers Avatar answered Sep 27 '22 23:09

Lieven Keersmaekers