How To Date filter with Devexpress XPO XPDataView
public string GetCreatedDate(string period, string column, string customFilterFrom = null, string CustomFilterTo = null)
{
string date = string.Empty; string filterexp = string.Empty;
DateTime dt = DateTime.Today;
switch (period.ToUpper())
{
case "CUSTOM":
date = new BetweenOperator(column, Convert.ToDateTime(customFilterFrom.Replace("/", "-")), Convert.ToDateTime(CustomFilterTo.Replace("/", "-"))).ToString();
break;
case "TODAY":
date = new BetweenOperator(column, dt, dt.AddDays(1)).ToString(); //string.Format("[{1}] = #{0}#", dt, column);//.ToString("MM/dd/yyyy")
break;
case "LASTDAY":
date = new BetweenOperator(column,dt.AddDays(-1),dt).ToString();
break;
case "THISYEAR":
date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, 4, 1), dt.AddDays(1)).ToString();
break;
case "THISMONTH":
date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), dt.AddDays(1)).ToString();
break;
case "LASTMONTH":
date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(-1), new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1)).ToString();
break;
case "THISWEEK":
int days = (DateTime.Now.DayOfWeek - DayOfWeek.Sunday) - 1;
DateTime thisweek = DateTime.Now.AddDays(-(days));
date = new BetweenOperator(column, thisweek, thisweek.AddDays(days)).ToString();
break;
case "LASTWEEK":
int diff = (DateTime.Now.DayOfWeek - DayOfWeek.Sunday) + 6;
DateTime mondayOfLastWeek = DateTime.Now.AddDays(-diff);
date = new BetweenOperator(column, mondayOfLastWeek, mondayOfLastWeek.AddDays(diff -6)).ToString();
break;
default:
date = string.Format("[{0}] = '{1}'", column, period);
break;
}
return date;
}
{
string date = string.Empty; string filterexp = string.Empty;
DateTime dt = DateTime.Today;
switch (period.ToUpper())
{
case "CUSTOM":
date = new BetweenOperator(column, Convert.ToDateTime(customFilterFrom.Replace("/", "-")), Convert.ToDateTime(CustomFilterTo.Replace("/", "-"))).ToString();
break;
case "TODAY":
date = new BetweenOperator(column, dt, dt.AddDays(1)).ToString(); //string.Format("[{1}] = #{0}#", dt, column);//.ToString("MM/dd/yyyy")
break;
case "LASTDAY":
date = new BetweenOperator(column,dt.AddDays(-1),dt).ToString();
break;
case "THISYEAR":
date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, 4, 1), dt.AddDays(1)).ToString();
break;
case "THISMONTH":
date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), dt.AddDays(1)).ToString();
break;
case "LASTMONTH":
date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(-1), new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1)).ToString();
break;
case "THISWEEK":
int days = (DateTime.Now.DayOfWeek - DayOfWeek.Sunday) - 1;
DateTime thisweek = DateTime.Now.AddDays(-(days));
date = new BetweenOperator(column, thisweek, thisweek.AddDays(days)).ToString();
break;
case "LASTWEEK":
int diff = (DateTime.Now.DayOfWeek - DayOfWeek.Sunday) + 6;
DateTime mondayOfLastWeek = DateTime.Now.AddDays(-diff);
date = new BetweenOperator(column, mondayOfLastWeek, mondayOfLastWeek.AddDays(diff -6)).ToString();
break;
default:
date = string.Format("[{0}] = '{1}'", column, period);
break;
}
return date;
}
Refer my original post in devexpress : Unable to filter date values in xpo DataSource
No comments:
Post a Comment