Click here to Skip to main content
15,878,231 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello sir,
My question Is
Can i Convert string date format to another string format ?

string currentdate= "04/28/2015" ("MM/dd/yyyy")

i want format this date in "28/04/2015" ("dd/MM/yyyy")

i ask this question because in project i got this dateformat("MM/dd/yyyy") from Storedprocedure and i have to display as"dd/MM/yyyy" in gridview
without changing storedprocedure because this sp used inalmost pages

please tell me how to do this ?
give some solution
Updated 23-Apr-15 9:27am
Sergey Alexandrovich Kryukov 23-Apr-15 15:28pm    
What have you tried so far?

The whole idea to work with strings representing data instead of data itself is utterly bad, counter-productive, but presently is a very typical behavior of poor developers. Don't go this way. Do everything with the type System.DateTime, not with the string. The string can only be on output and never on input. (Yes, serializers use strings, but they should use some fixed culture-neutral "round-trip" string representation, preferably UCT

This type has a number of ToString method with the culture parameters parameters (implementing IFormatProvider>) and/or string parameters representing format explicitly:[^].

For format, please see:[^],[^].

In rare cases when you have string representing time on input (you have to make sure they are really rare), you can use some of the methods Parse, ParseExact, TryParse or TryParseExact:[^].

Share this answer
TheRealSteveJudge 24-Apr-15 6:16am    
Exactly! 5*
Sergey Alexandrovich Kryukov 24-Apr-15 9:35am    
Thank you, Steve.
string currentDate = "04/28/2015";
DateTime.ParseExact(currentDate, "MM/dd/yyyy").ToString("dd/MM/yyyy")
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