My database is SQL Server 2008 and I have a query which returns some details filtered by date. In the WHERE close of the query I have something like this
WHERE (CONVERT (DATE, Attendance.in_time) = @inDate)
NOTE : Attendance.in_time
is a DateTime
column
Here I'm trying to get the date part only from in_time
and to compare it with @inDate
parameter in .net.
My problem is, in .NET we cant have only the data part of a DateTime. One option is to convert it to a string as follows
var inDate = InTime.Date.ToString("d");
But now the problem is Date and String cannot be compared in the SQL query?
Can anyone provide a solution?
EDIT : As requested in comments I'm showing full query here ...
public List<IAttendance> ShowAttendance(DateTime InDate, string pid, List<IAttendance> list)
{
string selectStatement = "SELECT Employee.Emp_ID, Employee.Initials + ' ' + Employee.Surname AS Name, Attendance.in_time, Attendance.out_time, Attendance.shift "+
"FROM Attendance INNER JOIN Employee ON Attendance.EID = Employee.Emp_ID "+
"WHERE (CONVERT (DATE, Attendance.in_time) = @inDate) AND (Attendance.PID = @pid) ";
//
}