按财政年度筛选日期

Filter Date by FinancialYear

我有一个 table 需要按财政年度过滤数据。

财政年度介于 April 1 of current yearMarch 31st of next year 之间。对于 example:The 当前年份是 2016 因此当前财政年度介于 April 1 2016March 31 2017.

table

Id    CenterId    SlNo        Date
 1        1         5        2016-01-09 10:51:43.480 
 2        2         10       2016-01-09 10:51:43.480  

我想获得 Slno 其中 CenterId=1Date will between current financial year

我担心的是Do i need another column of date for filtering financial year

非常感谢任何帮助?

不,您可以在不创建新列的情况下执行此操作。只需像这样计算当前财政年度日期:-

DateTime currentFinancialYearStartDate = new DateTime(DateTime.Today.Year, 4, 1);
DateTime currentFinancialYearEndDate = new DateTime(DateTime.Today.Year + 1, 3, 31); 

然后,只需像这样在您的过滤器中使用它们:-

var result = dbContext.Sample.Where(x => x.CenterId == 1 
                                      && x.Date >= currentFinancialYearStartDate 
                                      && x.Date <= currentFinancialYearEndDate)
                             .Select(x => x.Slno);