Wednesday, 29 May 2013

How to use DateTime object and accessing in different-2 property of that datetime object using c#

How to use DateTime object and accessing in different-2 property of that datetime object using c#



Step 1 : First create your website in asp.net and create one .aspx page .

Step2  : Open .aspx page source code .cs file




Step 3 : Access different-2 property of datetime object

  // accessing day property
   Response.Write("<br/>1. " + DateTime.Now.Day);

// accessing month property
Response.Write("<br/>2. " + DateTime.Now.Month);

// accessing year property
Response.Write("<br/>3. " + DateTime.Now.Year);

 // accessing minutes property
   Response.Write("<br/>4. " + DateTime.Now.Minute);

 // accessing hours property
Response.Write("<br/>4. " + DateTime.Now.Hour);

 // accessing second property
Response.Write("<br/>5. " + DateTime.Now.Second);

// accessing adding days in current day
Response.Write("<br/>6. " + DateTime.Now.AddDays(5));

 // accessing adding month in current month
Response.Write("<br/>7. " + DateTime.Now.AddMonths(5));

// accessing adding year in current year
Response.Write("<br/>8. " + DateTime.Now.AddYears(5));

// accessing minus year in current year
Response.Write("<br/>9. " + DateTime.Now.AddYears(-5));

// accessing minus months in current month
 Response.Write("<br/>10. " + DateTime.Now.AddMonths(-11));




Step 4 : This way you can access different-2 property of date time object.

Output will be:

1. 29
2. 1
3. 2012
4. 50
4. 16
5. 16
6. 2012-02-03 04:50:16 PM
7. 2012-06-29 04:50:16 PM
8. 2017-01-29 04:50:16 PM
9. 2007-01-29 04:50:16 PM
10. 2011-02-28 04:50:16 PM 







No comments:

Post a Comment

Thank you for your interest .