Linq query DateTime.Date.DayOfWeek

后端 未结 2 1182
抹茶落季
抹茶落季 2020-12-20 06:05

Trying to get only Thursdays of 1 year back

using (var context = new Context1())
{
      // Get 1 year back only Thursday
      var oneYearEarlier = DateTime         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 06:45

    This is a clever solution using EntityFunctions.DiffDays

    from his post:

    DateTime firstSunday = new DateTime(1753, 1, 7); 
    var bookings = from b in this.db.Bookings 
                   where EntityFunctions.DiffDays(firstSunday, b.StartDateTime) % 7 == 1 
                   select b;
    

提交回复
热议问题