i am using here one method and it is getting to perameters nullable DateTime type i want to get those records whoes created date match with my paremters
( i am using here view which returning date in this format (2014-01-29) ) ,and when i am passing start date (value of startDate is compalete datetime means it is {1/30/2014 12:00:00 AM}) , that's why it is not showing my complete records. please help me.
public IList
{
var data = session.Query
// var test = Convert.ToDateTime(Convert.ToDateTime(startDate).Date.ToString("yyyy-mm-dd"));
if (!string.IsNullOrWhiteSpace(startDate.ToString()) && !(string.IsNullOrWhiteSpace(endDate.ToString())))
{
data = data.Where(x => x.createddate >= startDate && x.createddate <= endDate).Distinct(x => x.Name).ToList();
}
if ((!string.IsNullOrWhiteSpace(startDate.ToString()) && (string.IsNullOrWhiteSpace(endDate.ToString()))))
{
data = data.Where(x => x.createddate >= startDate).Distinct(x => x.Name).ToList();
}
if ((string.IsNullOrWhiteSpace(startDate.ToString()) && (!string.IsNullOrWhiteSpace(endDate.ToString()))))
{
data = data.Where(x => x.createddate <= endDate).Distinct(x => x.Name).ToList();
}
if ((string.IsNullOrWhiteSpace(startDate.ToString()) && (string.IsNullOrWhiteSpace(endDate.ToString()))))
{
data = data.Where(x => x.createddate > DateTime.Now.AddDays(-7)).Distinct(x => x.Name).ToList();
}
return data;
}

Sanjay DholakiyaPosted Feb 26, 2014, 11:58 PM
Please use .Date everywhere.
For example,
data = data.Where(x => x.createddate.Date >= startDate.Date).Distinct(x => x.Name).ToList();
- Sanjay Dholakiya
Lawrence PondPosted Jan 30, 2014, 1:19 AM
This truncates the time element of the date that is giving you some of your problem. So by converting it to.ToShortDateString() your strip off the time element now your on you way.
Cheers