开发者

Linq query-dateOfBirth to age

Is is possible to turn a dateOfBirth in a linq query to an age within the query so i can do a comparis开发者_开发问答on to an int?

Cheers in advanced

Truez


It would be tricky or expensive to calculate the exact age for each record. Assuming you're really wanting to say something like "find me everyone 18 or over" it would be a better idea to work out the date of birth of someone who is exactly 18 today, and find everyone with a date of birth less than or each to that:

DateTime latestAdultBirth = DateTime.Today.AddYears(-18);
var adults = people.Where(person => person.dateOfBirth < latestAdultBirth);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜