How to determine if birthday or anniversary occurred during date range

Given I have a birthday/anniversary DateTime, how can I determine if that date occurred during a specific date range? For example, Birthday = 1/2/2000 Date Range = 12/25/2008 - 1/3/2009 I need a method to determine whether or not this person's birthday happened during that date range - preferably in C#. I first went about changing the year of the birthday DateTime to match the date r

如何确定日期范围内是否有生日或周年纪念

鉴于我有生日/周年日期时间,我如何确定该日期是否在特定日期范围内发生? 例如, 生日= 1/2/2000 日期范围= 12/25/2008 - 1/3/2009 我需要一种方法来确定此人的生日是否发生在该日期范围内 - 最好是用C#。 我首先将生日DateTime的年份更改为与日期范围相匹配,然后检查“新”生日DateTime是否在日期范围的开始日期和结束日期之间......但是如果日期范围跨越不同年份,就像我上面的例子 - 我不得不添加一个讨厌的if语

Calculate age from date in textbox in C#

Possible Duplicate: Calculating age from birthday How do you calculate age in years, taking input from TextBox in the format dd/MM/yyyy ? eg input: txtDOB.Text 20/02/1989 (String format) output: txtAge.Text 23 您可以使用DateTime的Substract方法(链接),然后使用Days属性来确定实际的年龄: DateTime now = DateTime.Now; DateTime givenDate = DateTime.Parse(input); int days = now.Subtract(gi

从C#中的文本框中的日期计算年龄

可能重复: 从生日计算年龄 如何计算年龄,以格式dd/MM/yyyy TextBox输入? 例如 输入:txtDOB.Text 20/02/1989(字符串格式) 输出:txtAge.Text 23 您可以使用DateTime的Substract方法(链接),然后使用Days属性来确定实际的年龄: DateTime now = DateTime.Now; DateTime givenDate = DateTime.Parse(input); int days = now.Subtract(givenDate).Days int age = Math.Floor(days / 365.24219) TimeSpan TS = Dat

Calculate # of Years Alive in C# WinForm

This question already has an answer here: How do I calculate someone's age in C#? 64 answers Try something like this: private void button1_Click(object sender, EventArgs e) { DateTime sonsBirthday = DateTime.Parse(txtSonsBirthday.Text).Date; DateTime now = DateTime.Now; TimeSpan timeSpan = now - sonsBirthday; //timeSpan = Convert.TimeSpan(lblTimeAlive); // old lb

计算C#WinForm中的活跃年数

这个问题在这里已经有了答案: 我如何用C#计算某人的年龄? 64个答案 尝试这样的事情: private void button1_Click(object sender, EventArgs e) { DateTime sonsBirthday = DateTime.Parse(txtSonsBirthday.Text).Date; DateTime now = DateTime.Now; TimeSpan timeSpan = now - sonsBirthday; //timeSpan = Convert.TimeSpan(lblTimeAlive); // old lblTimeAlive.Text = timeSpan.ToString();

age calculation

Possible Duplicate: How do I calculate someone's age in C#? I am trying to create a form where a client's date of birth is entered and his age is displayed automatically in txtAge: private void Form3_Load(object sender, EventArgs e) { dtpDob.Value = DateTime.Today.Date; SqlConnection conn = new SqlConnection(); } private void dtpDOB_Leave(object sender, System.EventA

年龄计算

可能重复: 我如何用C#计算某人的年龄? 我正在尝试创建一个表单,其中输入了客户的出生日期,并且他的年龄在txtAge中自动显示: private void Form3_Load(object sender, EventArgs e) { dtpDob.Value = DateTime.Today.Date; SqlConnection conn = new SqlConnection(); } private void dtpDOB_Leave(object sender, System.EventArgs e) { System.DateTime dob = default(System.DateTime);

Exact age calculation

Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be silly but and I don't have issues with my age but sometimes it is good to calculate the exact age of someone, I have introduced my birthdate in my profile (01/12/1975) "dd/mm/yyyy" and it calculated 33 and I'm 32 actually still, isn't it better to calculate the exact age? Maybe DateTim

精确的年龄计算

可能重复: 我如何用C#计算某人的年龄? 也许这可能很愚蠢,但我的年龄没有问题,但有时计算某个人的确切年龄是很好的,我在我的个人资料中介绍了我的出生日期(01/12/1975)“dd / mm / yyyy “它计算了33,我实际上仍然是32,计算确切的年龄不是更好吗? 也许 DateTime dt1 = DateTime.Now; TimeSpan dt2; dt2 = dt1.Subtract(new DateTime(1975, 12, 01)); double year = dt2.TotalDays / 365; 一年的结果是32.7740567

Property or indexer cannot be assigned to

I'm capturing date of Birth and Date of Diagnosis in database and would like to calculate age in years by Diagnosis date. This is my code. But I have error following error. Error 2 Property or indexer 'LightSwitchApplication.Patient.AgeAtDiagnosis' cannot be assigned to -- it is read only partial void AgeAtDiagnosis_Compute(ref int result) { // Set result to the desired

属性或索引器不能分配给

我在数据库中记录了出生日期和诊断日期,并且想要根据诊断日期计算年龄。 这是我的代码。 但我有错误跟随错误。 错误2属性或索引器'LightSwitchApplication.Patient.AgeAtDiagnosis'不能分配给 - 它是只读的 partial void AgeAtDiagnosis_Compute(ref int result) { // Set result to the desired field value AgeAtDiagnosis = DateofDiagnosis.Year - DateofBirth.Year; if (DateofBirth

what is the simplest and correct way to calculate age?

Possible Duplicate: How do I calculate someone's age in C#? Hi, Simple question. Need to calculate age and only allow people who are 21. Do you use timespan? so given somebody inputting a date i need to check if they are >=21. suggestions? The easiest way isn't to actually calculate their age - it's to see whether their birthday is after your limit: DateTime twentyOneYea

计算年龄的最简单和最正确的方法是什么?

可能重复: 我如何用C#计算某人的年龄? 嗨,简单的问题。 需要计算年龄,只允许21岁的人使用时间跨度? 所以有人输入日期我需要检查他们是否> = 21。 建议? 最简单的方法不是真正计算他们的年龄 - 而是看他们的生日是否在你的极限之后: DateTime twentyOneYearsAgo = DateTime.Today.AddYears(-21); if (birthDate > twentyOneYearsAgo) { // Sorry, you're too young } 请注意,在闰年的2月29日, A

how can i calculate age by datetimepicker

Possible Duplicate: How do I calculate someone's age How can i calculate age using datetimepicker in c#? Strictly speaking, TimeSpan age = DateTime.Now - dateTimePicker.Value; However, figuring out someone's "age" is only slightly more complicated. int years = DateTime.Now.Year - dateTimePicker.Value.Year; if(dateTimePicker.Value.AddYears(years) > DateTime.Now) year

我怎么能通过datetimepicker计算年龄

可能重复: 我如何计算某人的年龄 我如何计算在c#中使用datetimepicker的年龄? 严格来讲, TimeSpan age = DateTime.Now - dateTimePicker.Value; 然而,找出某人的“年龄”只是稍微复杂一些。 int years = DateTime.Now.Year - dateTimePicker.Value.Year; if(dateTimePicker.Value.AddYears(years) > DateTime.Now) years--; 由于年份的长短不一,您必须这样做,而不是依赖像TimeSpan这样的代表特定时间的结构(

Simple Age Calculator base on date of birth in C#

This question already has an answer here: How do I calculate someone's age in C#? 64 answers Contrary to the comments, TimeSpan does not help you here, because a year is not a fixed length of time. That in turn leads to your expressed aim being very strange indeed. You really shouldn't be representing a date as a fractional number with the first two digits being months and the thir

简单年龄计算器基于C#中的出生日期

这个问题在这里已经有了答案: 我如何用C#计算某人的年龄? 64个答案 与评论相反, TimeSpan在这里并没有帮助你,因为一年不是固定的时间。 这反过来导致你表达的目标确实很奇怪。 您实际上不应该将日期表示为小数,前两位数字为月份,第三位和第四位数字为天数。 时间就是这样。 (例如,2014.0131与2014.0201之间的差异远大于2014.0130与2014.0131之间的差异)。 用年,月,日来表示年龄会更好。 我的野田时间库

Age in years from DateTime (Date of birth)

Duplicate How Can I calculate Someone's Age in C#? I have a datetime variable that represents the date of birth of a user. How can I get the age in years from this? Update I want a precise birthday, so 30.45 years or something. 尝试以下(假设出生日期存储在dtDOB ): public int getAgeInYears { TimeSpan tsAge = DateTime.Now.Subtract(dtDOB); return new DateTime(tsAge.Ticks).Year -

来自DateTime的年龄(出生日期)

重复 我如何计算C#中的某人的年龄? 我有一个datetime变量,表示用户的出生日期。 我怎样才能从这个年龄获得年龄? 更新我想要一个精确的生日,所以30.45年什么的。 尝试以下(假设出生日期存储在dtDOB ): public int getAgeInYears { TimeSpan tsAge = DateTime.Now.Subtract(dtDOB); return new DateTime(tsAge.Ticks).Year - 1; } 从Jeff的问题的答案中被盗: DateTime now = DateTime.Now; int age = now.Ye