Smart    Lucky

Smart Lucky

  • NA
  • 555
  • 637.7k

DateTime Format Problem Not Getting Exact Result

Jan 30 2014 12:30 AM
  Hi dudes
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<GetCompanybyClicks> GetCompanyByClicks(DateTime? startDate, DateTime? endDate)
{
var data = session.Query<GetCompanybyClicks>().ToList();
// 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;
}


Answers (2)