-11
namespace Computerization_of_Health_Records {
  public class HealthProfile {
    //auto implemented property Firstname implicitly creates an 
    //instance variable for the patients first name
    public string FirstName { get; set; }

    //auto implemented property Firstname implicitly creates an 
    //instance variable for the patients last name
    public string LastName { get; set; }

    //auto implemented property Gender implicitly creates an 
    //instance variable for the patients gender
    public string Gender { get; set; }

    //auto implemented property birthday implicitly creates an 
    //instance variable for the patients birth day
    public Int32 Birthday { get; set; }

    //auto implemented property height implicitly creates an 
    //instance variable for the patients height
    public string Height { get; set; }

    //auto implemented property weight implicitly creates an 
    //instance variable for the patients weight
    public string Weight { get; set; }

    public string maxHeartRate { get; set; }

    public string bmi { get; set; }

    public string Age { get; set; }


    //constructor to initialize first name, last name, gender, birthday, birth month,
    //Birth year, height and weight.
    public HealthProfile(string first, string last, string gender, Int32 birthday, string height, string weight, string maxHrtRate) {
      FirstName = first;
      LastName = last;
      Gender = gender;
      Birthday = birthday;
      Height = height;
      Weight = weight;
      maxHeartRate = maxHrtRate;
    }
  }
}
Derek Wang
  • 10,098
  • 4
  • 18
  • 39
Relaxsingh
  • 11
  • 5
  • 1
    What's "TIA"? Why so much code unrelated to the problem? – tadman Aug 22 '17 at 17:22
  • What does any of the code in the question have to do with calculating a birthdate? –  Aug 22 '17 at 17:24
  • Your birthday variable is Int32. You won't be able to calculate age unless it's atleast timespan value in there. – Amit Kumar Singh Aug 22 '17 at 17:25
  • 1
    You don't have a birthdate in your code, and you already specify an age. Please correct the question to be reasonable and reduce the amount of code that is unneeded. It's confusing the situation. – Bob G Aug 22 '17 at 17:26
  • Why would `Age` be a `string` property? – NetMage Aug 22 '17 at 17:44
  • 1
    Use some common sense. How would you calculate someone's age if you were doing it manually using a pencil and paper? Figure that out and write down the steps. Then translate those steps to code. If you have trouble translating any of the steps to code, then ask a question about that step. – Chris Dunaway Aug 22 '17 at 17:53
  • @tadman: TIA = [thanks in advantage](https://meta.stackoverflow.com/questions/288160/no-thanks-damn-it). Great that we have it in titles now. – Thomas Weller Sep 14 '17 at 19:26
  • @ThomasWeller I'll just remove that from the title and pretend we never saw it. Yikes. – tadman Sep 14 '17 at 19:27
  • Duplicate of https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c?noredirect=1&lq=1 – Jamil Jan 15 '19 at 12:29

1 Answers1

1

Pass date of birth to the below function in UTC format(as it is a standard date format).

public static string GetAge(DateTime dob)
{
    DateTime todayDateUtc = DateTime.UtcNow;
    DateTime pastYearDate;
    int years = 0;
    string age;
    int days;

    if(DateTime.UtcNow > dob) {
        years = new DateTime(DateTime.UtcNow.Subtract(dob).Ticks).Year - 1;
    }

    pastYearDate = dob.AddYears(years);
    days = todayDateUtc.Subtract(pastYearDate).Days;
    age = years + " years " + days + " days";

    return age;
}
pim
  • 12,019
  • 6
  • 66
  • 69