Най-добрият начин е да форматирате въведеното в dd/MMM /yyyy формат. По-добре помага на SqlServer да идентифицира месеца и деня. Горещо препоръчвам да използвате MMM формат винаги, когато комуникирате със SqlServer.
DateTime fromDate, toDate;
fromDate = DateTime.Parse(dtpFrom.Text);
toDate = DateTime.Parse(dtpTo.Text);
SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(80), i.InvDate,3) AS InvDate,
i.InvoiceNo,
i.EmployerCode,
i.TaxAmount + i.SubTotal AS Amount,
'' AS Payment,
pd.GivenName
FROM dbo.Invoice i
INNER JOIN dbo.PatientDetails pd ON (pd.MedicalRecordID = i.MedicalRecordID)
WHERE datediff(d, '" + fromDate.ToString("dd/MMM/yyyy") + "', i.InvDate) >=0
AND datediff(d, '" + toDate.ToString("dd/MMM/yyyy") + "', i.InvDate) <=0", objConn);
или ако имате някакво ограничение да направите както по-горе, конвертирайте входа с помощта на CONVERT()
SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(80), i.InvDate,3) AS InvDate,
i.InvoiceNo,
i.EmployerCode,
i.TaxAmount + i.SubTotal AS Amount,
'' AS Payment,
pd.GivenName
FROM dbo.Invoice i
INNER JOIN dbo.PatientDetails pd ON (pd.MedicalRecordID = i.MedicalRecordID)
WHERE datediff(d, CONVERT(datetime, '" + dtpFrom.Text + "', 105 ), i.InvDate) >=0
AND datediff(d, CONVERT(datetime, '" + dtpTo.Text + "', 105 ), i.InvDate) <=0", objConn);