如何从出生日期算起年龄并显示在文本框中. [英] How to calculate age from date of birth and display in a textbox.

查看:278
本文介绍了如何从出生日期算起年龄并显示在文本框中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在一个文本框上使用日历扩展程序,我想从所选日期计算年龄,选择日期后,计算出的年龄应立即显示在另一个文本框中.怎么做?另一个问题是日历扩展程序的OnClientDateSelectionChanged事件在我尝试调用方法的过程中不起作用.请提供帮助.

Hello,

I am using a calendar extender on a textbox and i want to calculate age from the selected date and as soon as the date is selected, calculated age should be shown in another textbox. How it can be done? Another problem is OnClientDateSelectionChanged event of calendar extender is not working on which i tried to call a method. Please help.

推荐答案

int now = int.Parse(DateTime.Today.ToString("yyyyMMdd"));
int dob = int.Parse(dateDOB.ToString("yyyyMMdd"));
string dif = (now - dob).ToString();
string age = "0";
if (dif.Length > 4)
    age = dif.Substring(0, dif.Length - 4);




谢谢,
Ambesha




Thanks,
Ambesha


DateTime d1=DateTime.Now ;
DateTime d2 = new DateTime(1978,4,5);
TimeSpan difference = d1.Subtract(d2);
difference.TotalDays/365.25).ToString();




or

//call function
int age= Age(DateTime.Parse("4/26/1973"));
//function
public static int Age(DateTime birthDate)
{
int years, months, days;
DateDiff(DateTime.Now, birthDate, out years, out months, out days);
return years;
}


祝您编码愉快!
:)


Happy Coding!
:)


http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c [ http://forums.asp.net/p/1082692/1604940.aspx [ ^ ]
http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c[^]

http://forums.asp.net/p/1082692/1604940.aspx[^]


这篇关于如何从出生日期算起年龄并显示在文本框中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆