The following query is returning a number of daily orders. I want to create another query that will return int number of orders in one month. The problem is some months have 29days, some 30 or 31. Any help is appreciated!
public int GetNewDailyOrders()
{
return _DbContext.Carts.Where(x => x.Created >= DateTime.UtcNow.AddDays(-1)).Count();
}
>Solution :
public int GetMonthlyOrders(int month, int year)
{
return _DbContext.Carts.Count(x => x.Created.Year == year && x.Created.Month == month);
}
may be, you should consider support different timezones, summertime or not, something like this as well