问题描述
亲爱的所有人,
在我的数据库中,年龄是1946年,当我们得到的日志是2046年时,我们需要1946年作为b $ b计算Global.age。
请问我的代码有什么问题?
timespan = DateTime.Now.Subtract(Convert.ToDateTime(patientInfo [0]。 DOB));
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int i = 0; i< patientInfo.Length; i ++)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(patientInfo [i] .Type ==" OAS")
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(patientInfo [i] .DOB!= null&& patientInfo [i] .DOB!="")
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; timespan = DateTime.Now.Subtract(Convert.ToDateTime(patientInfo [i] .DOB));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; log.EventLog(" DOB输入OAS NRIC2" + patientInfo [0] .DOB);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;并且感谢您的帮助。
我和作为开发人员的企业新手。
Dear all,
In my database the age is 1946 and when we get the log is 2046,
we need 1946 as calculate the Global.age.
May I ask what wrong with my code?
timespan = DateTime.Now.Subtract(Convert.ToDateTime(patientInfo[0].DOB));
for(int i = 0; i< patientInfo.Length; i++)
{
if(patientInfo[i].Type == "OAS")
{
if (patientInfo[i].DOB != null && patientInfo[i].DOB != "")
{
timespan = DateTime.Now.Subtract(Convert.ToDateTime(patientInfo[i].DOB));
log.EventLog("DOB Enter OAS NRIC2 " + patientInfo[0].DOB);
}
}
} and thanks for the help.
I&amp;#39;m newbie in enterprise as developer.
推荐答案
这是一个计算年龄的函数
Here is a function for calculating age
public int CalculateAge(DateTime birthdate)
{
var today = DateTime.Today;
// Calculate the age.
var age = today.Year - birthdate.Year;
// Go back to the year the person was born in case of a leap year
if (birthdate > today.AddYears(-age)) age--;
return age;
}
这篇关于年龄计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!