从DOB计算年龄的函数,然后从指定的年龄范围过滤结果 [英] Function to Calculate Age from DOB then Filter Result from specified Age Range
问题描述
更新:请参阅澄清部分的评论部分。 THX。
我正在尝试设置一个从dob(dd / mm / yyyy)计算年龄的函数,然后获取结果年龄并确定它是否是在最小值到最大值范围内的真/假。我已经在线研究了以下功能,到目前为止已经提出了以下功能。有人请帮帮我吗?
UPDATE: PLEASE SEE COMMENTS SECTION FOR CLARIFICATION. THX.
Hi, I'm trying to set up a function that calculates age from dob (dd/mm/yyyy) then takes the resulting age and determines if it's true/false within a range of minimum to maximum. I've researched the following function online and so far have come up with the following. Would anyone please help me out?
/// <summary>
/// Function will be ran during criteria check
/// Must return a true or false value
/// Resulting function must be called CriteriaResult
/// </summary>
/// <returns>True False Result</returns>
public bool CriteriaResult(BsonDocument lead)
{
//TODO: Insert Criteria Logic
return true;
{
String dob = "dd/MM/yyyy";
DateTime dateOfBirth = DateTime.Parse( dob );
Int32 age = DateTime.Now.Year - dateOfBirth.Year;
}
if(Int32.TryParse(lead["Age"].ToString(), out age))
{
if(age <= 75 && age >= 45)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
推荐答案
推荐这个
Refer this one
protected void Button1_Click(object sender, EventArgs e)
{
DateTime Birth = new DateTime(1954, 7, 30);
DateTime Today = DateTime.Now;
TimeSpan Span = Today - Birth;
DateTime Age = DateTime.MinValue + Span;
// note: MinValue is 1/1/1 so we have to subtract...
int Years = Age.Year - 1;
int Months = Age.Month - 1;
int Days = Age.Day - 1;
Response.Write(Years.ToString() + " Years, " + Months.ToString() + " Months, " + Days.ToString() + " Days<br />");
}
TimeSpan年和月 [ ^ ]
问候......:笑:
TimeSpan Years and Months[^]
Regards..:laugh:
DateTime now = DateTime.Today;
int age = now.Year - birthday.Year;
if (now < birthday.AddYears(age)) age--;
return age.ToString();
请参考此链接 http://stackoverflow.com/questions/2194999/how-to-calculate-an-age-based一个生日 [ ^ ]
然后相应地将年龄存储在数组过滤器中
refer this link http://stackoverflow.com/questions/2194999/how-to-calculate-an-age-based-on-a-birthday[^]
then store the age in an array filter accordingly
这篇关于从DOB计算年龄的函数,然后从指定的年龄范围过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!