[c#] How to change date format from DD/MM/YYYY or MM/DD/YYYY to YYYY-MM-DD?

i need to change the format of my date string using C#

from : "06/16/2010"or "16/06/2010"

to : "2010-06-16"

can you please help me achieve this

thanks

This question is related to c#

The answer is


We can do something like this

DateTime date_temp_from = DateTime.Parse(from.Value); //from.value" is input by user (dd/MM/yyyy)
DateTime date_temp_to = DateTime.Parse(to.Value); //to.value" is input by user (dd/MM/yyyy)

string date_from = date_temp_from.ToString("yyyy/MM/dd HH:mm");
string date_to = date_temp_to.ToString("yyyy/MM/dd HH:mm");

Thank you


The following will do.

string datestring = DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);

String dt = Date.Now.ToString("yyyy-MM-dd");

Now you got this for dt, 2010-09-09