How to get all the birthdays of today?

后端 未结 5 1912
南方客
南方客 2021-01-23 09:21

Does anyone know how to make a Linq query that gets all the birthdays of today? The code below doesn\'t work :

var getBirthdays = 
    orgContext.CreateQuery<         


        
5条回答
  •  不要未来只要你来
    2021-01-23 10:07

    If c.BirthDate is nullable, you have to convert it to a datetime first:

    var getBirthdays = orgContext.CreateQuery()
                                 .Where(c => c.BirthDate != null && 
                                         (Convert.ToDateTime(c.BirthDate).Month == 
                                            DateTime.Now.Month) && 
                                          Convert.ToDateTime(c.BirthDate).Day == 
                                            DateTime.Now.Day))
                                 .ToList();
    

提交回复
热议问题