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

Top 5 Contributors of the Month

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

 Subscribe to Code Snippets

Convert Datetime all Formats

Posted By:Aarureddy@Anjireddy       Posted Date: December 10, 2010    Points: 15    Category: DateTime    URL: http://www.dotnetspark.com  

This is used for convert datetime all 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:


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