Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a string that have date i want to change into my required format:


string n = dateTimePicker1.Value.ToShortDateString();


this function return me a date as 07/11/2014 but i want it into 2014-07-11


how can i change it.........
Posted
Comments
Member 10891595 11-Jul-14 6:30am    
thnks a lot for help me

Quite easy:

C#
string n = dateTimePicker1.Value.ToString("yyyy-MM-dd");
 
Share this answer
 
C#
string fromFormat = "dd/MM/yyyy"; 
string toFormat = "yyyy-MM-dd";

DateTime newDate = DateTime.ParseExact("07/11/2014", fromFormat, CultureInfo.InvariantCulture);

string n = newDate.ToString(toFormat);
 
Share this answer
 
Comments
George Jonsson 11-Jul-14 21:49pm    
Why complicate the matter that much?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900