Reputation: 49
I need to get data of two or three years like from 'Jan, 2017 to March, 2019' or so. In my query I've separated properties for Year & Month which are compared with SYear(from Year - 2017), Tyear(to Year - 2019) and SMonth(from Month - 1(Jan)), TMonth(to Month - 3(March)). My query is only working for a similar year search like Jan 2017 to Dec 2017. But don't work for Jan 2017 to March 2019.
Here's my code:
var Bim = new BillingInfoPerMonthManager().GetAll().Where(x => (Convert.ToInt64(x.Year) >= SYear && Convert.ToInt64(x.Year) <= TYear) && (Convert.ToInt64(x.Month) >= SMonth && Convert.ToInt64(x.Month) <= TMonth)).ToList();
I need to search like 'Jan, 2017 to March, 2019' where SYear = 2017, TYear = 2019, SMonth = 1, TMonth = 3 and get data according to search.
How can I do this, please help.
Upvotes: 1
Views: 49
Reputation: 34152
Imagine that Year = 2017 and Month = 9 while this is in the range you want but month = 9 does not fit in Convert.ToInt64(x.Month) >= SMonth && Convert.ToInt64(x.Month) <= TMonth
try something like this:
var Bim = new BillingInfoPerMonthManager().GetAll()
.Where(x => (int.Parse(x.Year) * 12 + int.Parse(x.Month)) >= SYear * 12 + SMonth
&& (int.Parse(x.Year) * 12 + int.Parse(x.Month)) <= TYear * 12 + TMonth).ToList();
Upvotes: 4