Home  »  Articles  »  C#.Net  »

How to convert Date from one format to another in C#.Net

 Posted By : Manoranjan SahooPosted Date : 15/10/2010 12:16:38 PM Category : C#.Net Points : 3

Use below code to change dateformat of an inputted date.

using System.Globalization;
IFormatProvider culture = new CultureInfo("en-US", true);
TextBox2.Text = DateTime.ParseExact(TextBox1.Text, "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault).ToString("yyyy-MM-dd");

The above code will update date from dd-MM-yyyy format to yyyy-MM-dd

if you want to change from dd-MM-yyyy hh:mm:ss to yyyy-MM-dd then follow the below code :

TextBox2.Text = DateTime.ParseExact(TextBox1.Text, "dd-MM-yyyy hh:mm:ss", culture, DateTimeStyles.NoCurrentDateDefault).ToString("yyyy-MM-dd");

Thank You.

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.