Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends
can someone link me to an article that talks about datetime, or provide solution for me on datetime substraction to get age, how to get the current day, how to get the current month,how to get the current week, an so on
Posted

See these articles:
http://www.codeproject.com/KB/datetime/[^]
There is more than enough information for you to learn everything about that topic.
For example to get the age:
DateTime bday = new DateTime(1980, 11, 8);
  DateTime now = DateTime.Today;
  int age = now.Year - bday.Year;
  if (bday > now.AddYears(-age)) age--;

  MessageBox.Show("Age is: "  + age.ToString());

To get today:
C#
MessageBox.Show("Today is: "  + DateTime.Now.ToShortDateString());
MessageBox.Show("Today is: " + DateTime.Now.ToShortDateString());
MessageBox.Show("Todays day is: " + DateTime.Now.Day.ToString());
MessageBox.Show("Todays month is: " + DateTime.Now.Month.ToString());
MessageBox.Show("Todays year is: " + DateTime.Now.Year.ToString());
MessageBox.Show("Todays weekday is: " + DateTime.Now.DayOfWeek.ToString());
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900