Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got date like this 12/27/2013 12:00:00 AM

how to convert this to '2013/12/27' in C#???

I tried using this DateTime.ParseExact(txtBxFromDate.Text, "yyyy/M/d", null);
Posted

Try this.
C#
DateTime.ParseExact(txtBxFromDate.Text, "yyyy/MM/dd", null);


reference: Date Format[^]
 
Share this answer
 
C#
DateTime currentDate = DateTime.Now();
string date = currentDate.toString("yyyy/MM/dd"); // [2014/01/09]
 
Share this answer
 
try like this:-
DateTime.ParseExact(txtDt.Text, "yyyy/MM/dd", null).ToString()


specify format instead of "yyyy/MM/dd" as you required.
 
Share this answer
 
string date = DateTime.Today.Date.ToString("yyyy/MM/dd");

Please have a look on this link, you will have a good idea.
convert date to string/[^]
 
Share this answer
 
v2
if txtBxFromDate.Text = "12/27/2013 12:00:00 AM" then
C#
txtBxFromDate.Text = "12/27/2013 12:00:00 AM";
DateTime dt = DateTime.ParseExact(txtBxFromDate.Text, "dd/MM/yyyy hh:mm:ss tt", null); 
txtboxOutput.Text = dt.Tostring("yyyy/MM/dd");

Happy Coding!
:)
 
Share this answer
 
try this

C#
string sDate = "12/27/2013";

        string[] dat = sDate.Split('/');
        string d = dat[1];
        string m = dat[0];
        string y = dat[2];
        string startDate = y + '/' + m + '/' + d;
 
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