I have a table stored in SQL Server database. One of the fields of the table is of type DATETIME. I also have a ASP Calendar whose date is compared with the DATETIME filed of Database.
The problem is I don’t want to compare the time. Only dates has to be compared. What is the SQL query for doing so.
This is what I used:
SqlCommand myCommand = new SqlCommand("
SELECT AUDIT.AUDIT_DETAILS, USERS.USER_NAME, AUDIT.DATE_TIME, IP
FROM USERS JOIN AUDIT ON (USERS.USER_ID = AUDIT.USER_ID)
WHERE USERS.USERS_NAME LIKE '%"+TextBox1.Text+"%' AND CONVERT(VARCHAR(10),AUDIT.DATE_TIME,110) like "+Calendar1.SelectedDate.Date+"'%'", conn);
I’m getting correct output in the SQL Server explorer but when run from browser through asp.net the query result is empty
You can get only date from Datetime in SQL like this
And after that you can compare to that value.