Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int GetAges(DateTime d1, DateTime d2)
- {
- return new DateTime(d2.Subtract(d1).Ticks).Year;
- }
- public static int GetAge(DateTime d1, DateTime d2)
- {
- return (int)((d2.Subtract(d1).Days / 365.25) + 0.001);
- }
- class Program
- {
- public static int GetAge(DateTime d1, DateTime d2)
- {
- return d2.Year - d1.Year - 1 +
- ((d2.Month > d1.Month || d2.Month == d1.Month && d2.Day >= d1.Day) ? 1 : 0);
- }
- public static int GetAges(DateTime d1, DateTime d2)
- {
- return (int)((d2.Subtract(d1).Days / 365.25) + 0.001);
- }
- static void Main(string[] args)
- {
- DateTime d1 = DateTime.Parse("01.01.2017 12:00:00");
- DateTime d2 = DateTime.Parse("01.01.2018 11:59:00");
- Console.WriteLine(GetAge(d1, d2));
- Console.WriteLine(GetAges(d1,d2));
- Console.ReadKey();
- }
- }
Add Comment
Please, Sign In to add comment