.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to convert the date time in all format.

Posted By:abhay       Posted Date: March 04, 2010    Points: 10    Category: DateTime    URL: http://www.dotnetspark.com  

How to convert the date time in all format. Many people are facing problem while converting date format.Here I am giving some tips to convert datetime format.
 

Many people are facing problem while converting date format.Here I am giving some tips to convert datetime format.

string date = "01/11/2009";//in the format month /date/year

DateTime dt = DateTime.Parse(date);

string result = dt.ToString("yyyy-MM-dd");//IN THE FORMAT YEAR /MONTH/DATE

string result1 = dt.ToString("yyyy-dd-MM");//IN THE FORMAT YEAR /DATE/MONTH

You have the date and time  and you don't want that time then 

string timeeXcludte = dt.ToShortDateString();

//dt having date with time 

How find date of tomorrow and yesterday as well as any previous date and future date



DateTime today = DateTime.Now.Date;

DateTime previousday = today.AddDays(-1);

DateTime tomorrow = today.AddDays(1);

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend