Exemplo n.º 1
0
        private static int CalculateAge(int empid)
        {
            EmployeeEntities _repo = new EmployeeEntities();
            EMP emp = new EMP();
            int age = 0;

            emp.EID = empid;
            var query = _repo.EMPs.Where(s => s.EID == emp.EID).Select(s => s.DOB).Single();

            //Console.WriteLine(query.DOB);
            System.DateTime dateOfBirth = Convert.ToDateTime(query);
            age = DateTime.Now.Year - dateOfBirth.Year;
            if (DateTime.Now.DayOfYear < dateOfBirth.DayOfYear)
            {
                age = age - 1;
            }

            return(age);
        }