Tuesday, March 12, 2013

C# CalcAge Algorithm



public static Int32 CalcAge(DateTime? data)
        {
            if (data != null)
            {
                var bDay = Convert.ToDateTime(data);
                var actualDate = DateTime.Now;
                var age = actualDate.Year - bDay.Year;
                if (bDay.Month < actualDate.Month || (actualDate.Month == bDay.Month & bDay.Day < actualDate.Day))
                    return age--;
                else
                    return age;
            }
            return 0;
        }



No comments: