jyoung12387

Days Alive

Mar 15th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DaysAlive
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             DateTime now = DateTime.Now;
  10.  
  11.             Console.Write("Enter your birthday: ");
  12.             string input = Console.ReadLine();
  13.  
  14.             if(DateTime.TryParse(input, out DateTime inputDateTime))
  15.             {
  16.                 TimeSpan daysPassed = now.Subtract(inputDateTime);
  17.                 Console.WriteLine($"Days passed since {inputDateTime.ToShortDateString()}: {daysPassed.Days:n0}");
  18.             }
  19.             else
  20.             {
  21.                 Console.WriteLine("Please enter a correct date");
  22.             }
  23.             Console.ReadLine();
  24.         }
  25.     }
  26. }
Add Comment
Please, Sign In to add comment