Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have string variable which hold the Date in
MM/dd/yyyy HH:mm:ss
format.and want to convert into
dd/MM/yyyy HH:mm:ss
Posted
Updated 11-Jan-12 1:58am
v2
Comments
johannesnestler 11-Jan-12 8:42am    
are you just converting between cultures? If yes, just use different Cultures on Conversion and no format string is needed.

Don't. Instead, convert it to a DateTime using either the users current DateTime settings or an absolute string. Then keep it as a DateTime until you actually need to format it for a display, and convert it then:
C#
string date = "01/11/2011 13:24:17";
DateTime dt;
if (DateTime.TryParseExact(date, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture,DateTimeStyles.None , out dt))
    {
    ...
    }

C#
string output = dt.ToString("dd/MM/yyyy HH:mm:ss");
 
Share this answer
 
VB
Try this

Convert.ToDateTime(DateFrom.SelectedDate).ToString("yyyyMMdd")

and this to convert the date time to string with your special format

string CurrentTime = DateTime.Now.ToString("ddMMyyyy")



and you can see My answer[^] when i answer your friend before
 
Share this answer
 
Try this

C#
string date = "01/11/2011 13:24:17";
string  dt = Convert.ToDateTime(date).ToString("dd/MM/yyyy hh:mm:ss");
 
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