答案 0 :(得分:0)
非常简单:
var under23 = DateTime.Today.AddYears(-23);
var clients = db.Clients.Where(m => m.ClientDOB > under23);
基本上,你只是从当前日期减去23年,然后查询DOB大于那个的客户,即他们出生的时间超过23年,使他们不到23岁。 / p>
答案 1 :(得分:0)
以下是您可以使用的逻辑
DateTime date=DateTime.Now;
var expectedMinDate=date.AddYears(-23);
DateTime clientBirthDate=Convert.ToDateTime("23/08/1993");
if(clientBirthDate>expectedMinDate)
{
Console.Write("Smaller than 23");
}
else
{
Console.Write("Greater than or equal to 23");
}
答案 2 :(得分:0)
DateTime birthday = new DateTime(1995, 7, 30);
var age = GetAge(birthday);
if (age < 23)
{
// do something
}
public int GetAge(DateTime dob)
{
var today = DateTime.Today;
var age = today.Year - dob.Year;
if (dob > today.AddYears(-age))
age--;
return age;
}