C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Count How Many Days Old You are ?
WhatsApp
Shridhar Sharma
Jun 03
2015
2
k
0
0
DateTimetxt.rar
DateTime d1 =
new
DateTime();
DateTime d2 =
new
DateTime();
Console.WriteLine(
"Enter today's date in year/month/date"
);
d2 = Convert.ToDateTime(Console.ReadLine()).Date;
Console.WriteLine(
"enter your birthdate"
);
d1 = Convert.ToDateTime(Console.ReadLine()).Date;
if
(d2 > d1)
{
TimeSpan difference = d2 - d1;
// using (StreamWriter sw = new StreamWriter("E:\\Shridhar\\Birthday.txt")) ;
Console.WriteLine(
"You are "
+ difference.Days +
" days old. "
);
}
else
{
Console.WriteLine(
"today's date should be greater than your birthdate ."
);
}
Console.ReadKey();
.Net
C#
datetime
Up Next
Count How Many Days Old You are ?