知道怎么看出一个人的年龄龄怎样才能算出他的出生日期

在excel中,已知某员工的出生日期,用什么函数能自动算出他年龄?_百度知道
在excel中,已知某员工的出生日期,用什么函数能自动算出他年龄?
提问者采纳
=VALUE(YEAR(NOW()))-VALUE(YEAR(A1))-1设以上是A2单元格计算年龄的公式内容,A1是出生日期,则A2是年龄!注:A2不能为日期格式!!!
提问者评价
其他类似问题
6人觉得有用
为您推荐:
其他3条回答
A1:A2:A3:为=A1-A2,之后把A3单元格格式改成,自定义类的:yy-m-d得到25-11-20,这就是他的实足年龄,改成yy也可以,可以得到25.
我只知道用现在的年份减去出生的年份(如=)。
=YEAR(TODAY()) - XX
您可能关注的推广
excel的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁“一个人竟有三个年龄” 为更正年龄他奔波7年无果
何伟国的身份证、招工档案以及户籍证明上写的出生年月都不相同 (记者 张哲 摄)
  红网湘潭站3月17日讯(湘潭晚报记者 王超)家住岳塘区东坪街道的何伟国,这辈子算过不计其数的账。可有一笔账,老何却始终没能算明白。原来,他竟有3个不同的“年龄”。因为年龄的“差异”问题,何伟国不仅错过了许多本该享有的权益,还为此奔波了7年之久。如今,疾病缠身的老何实在跑不动了,无奈之下,他只好托家人向湘潭晚报反映,希望早日改回真实年龄。“人一辈子,不就指望着活个明白吗?”3月16日,何伟国对我们说。
  年龄难确定,领养老金遇阻
  原籍档案上显示的出生日期是1951年3月,身份证、户口本上标注的出生日期是1954年4月,招工登记表上填写的出生日期是1956年5月。市民何伟国就遇上了这样的“年龄尴尬”。
  何伟国是三角坪粮库的一名退休工人。近些年,看着身边的同龄人都陆续领上了养老金,何伟国的心里酸溜溜的。
  何伟国心里感到酸,并非是嫉妒同伴享受到了这份福利待遇,而是他觉得自己错过这趟“班车”,实在有点“冤”。
  因为各种原因,导致他名下出现了3个不同的年龄。正因为如此,他被有关部门婉拒了领取养老金的请求。
  为了努力成为“达标”人群,何伟国前后花了7年时间来证明自己的真实年龄。随后,又辗转多路搜集人证、物证,可最终还是收效甚微。
  为了顺利上岗,曾擅自改过年龄
  到底是什么原因导致何伟国出现了3种年龄呢?就在我们不解时,何伟国要老伴找来了一个文件夹。
  文件夹里夹着的,是老何近些年四处搜罗来的一沓证明资料。在这些材料中,一份皱巴巴的原始户籍档案引起了我们的注意。
  从老何的口述中我们得知,这份档案是他2007年从原居住地派出所复印过来的。
  在这份登记年份为1962年的原始户籍档案上,不仅有何伟国的户籍住址、家庭成员等相关资料,还清楚地标注着他的出生年月为1951年3月。档案末尾,盖着一个“与原件核对无误”的公章印。
  “这是最早的资料,难道不足以证明我的真实年龄吗?”对于这份费了九牛二虎之力才弄来的证明材料,何伟国格外看重。
  何伟国透露,自己曾拿着这份最有力的证明材料找过相关部门,但都被对方予以了否决。对方告诉他,按照规定,领取养老金须以“招工资料显示的年龄”为准。很明显,何伟国招工登记表上填写的年龄为“日”, 不符合相关政策的要求。
  户籍上显示的年龄是1951年,怎么到招工材料上就成了1956年呢?对此,何伟国给出了自己的解释。
  何伟国介绍说,他31岁时,正好赶上三角坪粮库招工。由于招工的年龄是26岁以下的本市居民,当时为了顺利顶下父亲的职,他在填报年龄时擅自将自己的年龄改小了5岁。
  何时才能拥有真实年龄
  他很想知道答案
  根据原始档案登记的年龄,何伟国在3年前就能领到属于自己的那份养老金。谁料中途因为年龄不达标,他被屡次拒之门外。
  现在,何伟国和老伴的身体每况愈下,膝下的子女又无固定收入。眼看着家中光景一日不如一日,何伟国比过去更加着急了。
  到底何时才能拥有一个准确、真实的年龄,何伟国很想知道。
( 13:17:00) ( 9:12:38) ( 9:44:30) ( 11:02:08)知道一个人的身份证号码怎么推算出他爸爸的身份证号码以及他兄弟姐妹的号码?_百度知道
知道一个人的身份证号码怎么推算出他爸爸的身份证号码以及他兄弟姐妹的号码?
小时候见到别人算过。忘记了。
我有更好的答案
如果知道他们的出生日期就能算出来:前面的省市区号是相同的,后面的四位数也是相同的(第3位数是男单女双),中间加上他们的出生日期(XXXX年XX月XX日)就是他们各自的身份证号码。
不能,身份证的结构是前面六位地址码,中间八位生日日期,后面三位同龄顺序码,最后一位由政府机构专门用公示算出来的验证码
其他类似问题
为您推荐:
身份证号码的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁给定一个DateTime代表一个人的生日,我该如何计算自己的年龄?
本文地址 :CodeGo.net/4/
-------------------------------------------------------------------------------------------------------------------------
1. 对于原因,Jeff的代码似乎没有足够简单。这似乎更简单,更容易理解:
DateTime today = DateTime.T
int age = today.Year - bday.Y
if (bday & today.AddYears(-age)) age--;
这是一种奇怪的方式来做到这一点,但如果你的日期格式yyyymmdd并减去出生从当前日期起再落你已经得到了时代的最后4位数字:)
我不知道C#,但我相信这将工作在任何语言。
删除最后4位数=28。
var now = float.Parse(DateTime.Now.ToString("yyyy.MMdd"));
var dob = float.Parse(dateOfBirth.ToString("yyyy.MMdd"));
var age = (int)(now - dob);
或者,或者没有在错误检查省略了表单中的所有类型转换:
public static Int32 GetAge(this DateTime dateOfBirth)
var today = DateTime.T
var a = (today.Year * 100 + today.Month) * 100 + today.D
var b = (dateOfBirth.Year * 100 + dateOfBirth.Month) * 100 + dateOfBirth.D
return (a - b) / 10000;
我不知道怎么错了解决方案可以被接受。
正确的C#代码片段是由Michaelgrape汁
下面是测试代码片段:
DateTime bDay = new DateTime();
DateTime now = new DateTime();
MessageBox.Show(string.Format("Test {0} {1} {2}",
CalculateAgeWrong1(bDay, now),
CalculateAgeWrong2(bDay, now),
CalculateAgeCorrect(bDay, now)));
在这里,你有
public int CalculateAgeWrong1(DateTime birthDate, DateTime now)
return new DateTime(now.Subtract(birthDate).Ticks).Year - 1;
public int CalculateAgeWrong2(DateTime birthDate, DateTime now)
int age = now.Year - birthDate.Y
if (now & birthDate.AddYears(age)) age--;
public int CalculateAgeCorrect(DateTime birthDate, DateTime now)
int age = now.Year - birthDate.Y
if (now.Month & birthDate.Month || (now.Month == birthDate.Month && now.Day & birthDate.Day)) age--;
我不认为任何问题的答案到目前为止提供的文化是计算年龄的不同。参见 CodeGo.net,例如,东亚决战世纪,在西方。
任何真正的答案已经为包括本地化。策略模式很可能是为了在这个例子。
答案很简单,这是应用AddYears如下图所示,这是唯一多年添加到闰年的二月二十九日,获得的年二月二十八日的正确结果。
觉得3月1日是leaplings的生日,但两者都不是.net也没有任何官方的规则支持这一点,也没有逻辑解释为什么出生在二月应该有他们的生日的75%,再过一个月。
此外,一个适合于添加为一个扩展,通过这个你可以在最简单的方式获得年龄:
诠释年龄=birthDate.Age();
public static class DateTimeExtensions
/// &summary&
/// Calculates the age in years of the current System.DateTime object today.
/// &/summary&
/// &param name="birthDate"&The date of birth&/param&
/// &returns&Age in years today. 0 is returned for a future date of birth.&/returns&
public static int Age(this DateTime birthDate)
return Age(birthDate, DateTime.Today);
/// &summary&
/// Calculates the age in years of the current System.DateTime object on a later date.
/// &/summary&
/// &param name="birthDate"&The date of birth&/param&
/// &param name="laterDate"&The date on which to calculate the age.&/param&
/// &returns&Age in years on a later day. 0 is returned as minimum.&/returns&
public static int Age(this DateTime birthDate, DateTime laterDate)
age = laterDate.Year - birthDate.Y
if (age & 0)
age -= Convert.ToInt32(laterDate.Date & birthDate.Date.AddYears(age));
现在,运行这个测试:
class Program
static void Main(string[] args)
RunTest();
private static void RunTest()
DateTime birthDate = new DateTime();
DateTime laterDate = new DateTime();
string iso = "yyyy-MM-dd";
for (int i = 0; i & 3; i++)
for (int j = 0; j & 3; j++)
Console.WriteLine("Birth date: " + birthDate.AddDays(i).ToString(iso) + " Later date: " + laterDate.AddDays(j).ToString(iso) + " Age: " + birthDate.AddDays(i).Age(laterDate.AddDays(j)).ToString());
Console.ReadKey();
关键日期的例子是这样的:
出生日期:稍后日期:年龄:11
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
而对于较后日期:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
Birth date:
Later date:
int age = (int) ((DateTime.Now - bday).TotalDays/365.242199);
这似乎有一年改变的权利日期。 (我当场测试高达107岁)
我迟到了,但这里有一个班轮:
int age = new DateTime(DateTime.Now.Subtract(birthday).Ticks).Year-1;
这是这里的版本。它的工作原理,它是相当简单的。它的主意,因为杰夫的,但我认为这是一个更清楚一点它分离出来减去一个逻辑,所以这是一个比较容易理解。
public static int GetAge(this DateTime dateOfBirth, DateTime dateAsAt)
return dateAsAt.Year - dateOfBirth.Year - (dateOfBirth.DayOfYear & dateAsAt.DayOfYear ? 0 : 1);
你可以扩大三元运算符,使其更加清晰,如果你认为这种事情还不清楚。
这样做是为上DateTime,但很明显,你可以抓住的一行代码,做的工作,并把它放在任何地方。在这里,我们的另一个重载传递中DateTime.Now,只是
二,主要问题要解决是:
1。计算出精确的年龄-在年,月,日等
2。计算一般认为年龄-不在乎他们究竟多大年纪,他们只关心他们的时候在本年度的生日是。
DateTime birth = DateTime.Parse("1.1.2000");
DateTime today = DateTime.T
//we usually don't care about birth time
TimeSpan age = today -
//.NET FCL should guarantee this as precise
double ageInDays = age.TotalD //total number of days ... also precise
double daysInYear = 365.2425;
//statistical value for 400 years
double ageInYears = ageInDays / daysInY //can be shifted ... not so precise
解决方案2是一个是不是在测定中总年龄如此精确,但被认为是准确的人。人们用它,当他们“手动”计算自己的年龄:
DateTime birth = DateTime.Parse("1.1.2000");
DateTime today = DateTime.T
int age = today.Year - birth.Y //people perceive their age in years
today.Month & birth.Month
((today.Month == birth.Month) && (today.Day & birth.Day))
age--; //birthday in current year not yet reached, we are 1)
//+ no birthday for 29.2. guys ... sorry, just wrong date for birth
这是我首选的解决方案
我们或他们转移在闰年的天数
我已经把那里的可读性一点行
只是多一个音符...我会创建2个静态的它,一为第二
public static int GetAge(DateTime bithDay, DateTime today)
//chosen solution method body
public static int GetAge(DateTime birthDay)
return GetAge(birthDay, DateTime.Now);
另一项函数,但不是在网上,有点精上找到:
public static int GetAge(DateTime birthDate)
DateTime n = DateTime.N // To avoid a race condition around midnight
int age = n.Year - birthDate.Y
if (n.Month & birthDate.Month || (n.Month == birthDate.Month && n.Day & birthDate.Day))
只是两件事情,在我的心里:怎么样从做公历国家的人?在服务器特定的文化,我认为。我绝对0的了解实际工作与亚洲的日历,我不知道是否有一种简单的方法来转换日历日之间,但以防万一你想知道那些中国人从4660年:-)
许多年前,为客户端提供在我的网站年龄计算器噱头,我写了一个函数来计算年龄的一小部分。这是一个函数到C#的快速端口(从PHP版本)。恐怕我还没有能够测试C#版本,但希望你享受所有的
(诚然,这是一个有点噱头的堆栈溢出profile的目的,但也许读者会发现使用它。:-))
double AgeDiff(DateTime date1, DateTime date2) { double years = date2.Year - date1.Y /*
* If date2 and date1 + round(date2 - date1) are on different sides
* of 29 February, then our partial year is considered to have 366
* days total, otherwise it's 365. Note that 59 is the day number
* of 29 Feb.
*/ double fraction = 365
+ (DateTime.IsLeapYear(date2.Year) && date2.DayOfYear &= 59
&& (date1.DayOfYear & 59 || date1.DayOfYear & date2.DayOfYear)
? 1 : 0); /*
* The only really nontrivial case is if date1 is in a leap year,
* and date2 is not. So let's handle the others first.
*/ if (DateTime.IsLeapYear(date2.Year) == DateTime.IsLeapYear(date1.Year))
return years + (date2.DayOfYear - date1.DayOfYear) / /*
* If date2 is in a leap year, but date1 is not and is March or
* beyond, shift up by a day.
*/ if (DateTime.IsLeapYear(date2.Year)) {
return years + (date2.DayOfYear - date1.DayOfYear
- (date1.DayOfYear &= 59 ? 1 : 0)) / } /*
* If date1 is not on 29 February, shift down date1 by a day if
* March or later. Proceed normally.
*/ if (date1.DayOfYear != 59) {
return years + (date2.DayOfYear - date1.DayOfYear
+ (date1.DayOfYear & 59 ? 1 : 0)) / } /*
* Okay, here date1 is on 29 February, and date2 is not on a leap
* year. What to do now? On 28 Feb in date2's year, the ``age''
* should be just shy of a whole number, and on 1 Mar should be
* just over. Perhaps the easiest way is to a point halfway
* between those two: 58.5.
*/ return years + (date2.DayOfYear - 58.5) /}
我已经花了这方面的工作,并与该来计算年,月,日的年龄。我测试过对2月29日问题和闰年,它似乎工作,我会很感激任何反馈:
public void LoopAge(DateTime myDOB, DateTime FutureDate)
int years = 0;
int months = 0;
int days = 0;
DateTime tmpMyDOB = new DateTime(myDOB.Year, myDOB.Month, 1);
DateTime tmpFutureDate = new DateTime(FutureDate.Year, FutureDate.Month, 1);
while (tmpMyDOB.AddYears(years).AddMonths(months) & tmpFutureDate)
if (months & 12)
months = months - 12;
if (FutureDate.Day &= myDOB.Day)
days = days + FutureDate.Day - myDOB.D
if (months & 0)
months = months + 12;
DateTime.DaysInMonth(
FutureDate.AddMonths(-1).Year, FutureDate.AddMonths(-1).Month
) + FutureDate.Day - myDOB.D
//add an extra day if the dob is a leap day
if (DateTime.IsLeapYear(myDOB.Year) && myDOB.Month == 2 && myDOB.Day == 29)
//but only if the future date is less than 1st March
if (FutureDate &= new DateTime(FutureDate.Year, 3, 1))
保持简单(也可能是愚蠢的:))。
DateTime birth = new DateTime(, 01, 00, 00, 00);
TimeSpan ts = DateTime.Now -
Console.WriteLine("You are approximately " + ts.TotalSeconds.ToString() + " seconds old.");
据我所知,闰年,一切的最好的方法是:
DateTime birthDate = new DateTime();int age = (int)Math.Floor((DateTime.Now - birthDate).TotalDays / 365.25D);
希望这会有所帮助。
这里是一个解决方案。
DateTime dateOfBirth = new DateTime();
DateTime currentDate = DateTime.N
int ageInYears = 0;
int ageInMonths = 0;
int ageInDays = 0;
ageInDays = currentDate.Day - dateOfBirth.D
ageInMonths = currentDate.Month - dateOfBirth.M
ageInYears = currentDate.Year - dateOfBirth.Y
if (ageInDays & 0)
ageInDays += DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
ageInMonths = ageInMonths--;
if (ageInMonths & 0)
ageInMonths += 12;
ageInYears--;
if (ageInMonths & 0)
ageInMonths += 12;
ageInYears--;
Console.WriteLine("{0}, {1}, {2}", ageInYears, ageInMonths, ageInDays);
本文标题 :如何计算一个人的年龄在C#?
本文地址 :CodeGo.net/4/
Copyright (C) 2014 CodeGo.net 沪ICP备号 联&系& c&o&d&e&g&o &@&1&2&6&.&c&o&m

我要回帖

更多关于 王倩一个人资料年龄 的文章

 

随机推荐