Asp Net Source.com
What's ASP.NET?

AspNetSource.com's BLOG

AJAX, ASP.NET, C#, CSS, Design, .NET Framework, Javascript, SQL, VB.NET, etc.

Convert string to datetime Using C#

Posted by Tihomir Ivanov on 02 January 2010 13:37
Rating: 0.00

Sometimes you may have strings to represent dates (ex. 20100102 that represents 2010 January 2), here's an example how it can be converted to DateTime:

string dtString = "20100102";

IFormatProvider culture = new CultureInfo("en-EN", false);

DateTime dt = DateTime.ParseExact(dtString, "yyyyMMdd", culture, DateTimeStyles.NoCurrentDateDefault);

Now, if you want to convert DateTime variable to string in the format above, here's an example how it can be done:

String dtNewString = String.Format("{0:dd/MM/yyyy}", dt);

 

 Comments:
in Posted by asased on 08 November 2010 06:45   Rating: 0
very poor
 
Our Sponsors:  Asp.net file upload component  |   Flash file uploader  |  ASP.NET Hosting