In addition to my previous post, where I was calculating age based on birthdates. If we go the other way around and pretend that we have an age span instead; an age 'from' and 'to' we can easily convert those to represent the datespan that we are interested in the following way.
public class Agespan
{
public int AgeFrom { get; set; }
public int AgeTo { get; set; }
public DateTime DateFrom
{ get
{
{
return DateTime.Now.Date
.AddYears(-AgeTo - 1)
.AddDays(1);
}
}
}
public DateTime DateTo
{
get
{
return DateTime.Now.Date
.AddYears(-AgeFrom)
.AddHours(23)
.AddMinutes(59)
.AddSeconds(59);
}
}
}
Now we can in instantiate our "Agespan" object and use our dates on the object instead.
var agespan = new Agespan { AgeFrom = 24, AgeTo = 55 };
1a2bc646-7d18-4eb0-8d4b-2fd001d198fe|0|.0