TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Count How Many Days Old You are ?
Shridhar Sharma
Jun 03
2015
Code
1.8
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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();
C#
datetime
.Net