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
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 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With