Click here to Skip to main content
15,949,686 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
thanx
Posted
Updated 23-Apr-15 9:27am
v2
Comments
Sergey Alexandrovich Kryukov 23-Apr-15 15:28pm    
What have you tried so far?
—SA

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: https://msdn.microsoft.com/en-us/library/system.datetime.tostring%28v=vs.110%29.aspx[^].

For format, please see:
https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^].

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: https://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
Comments
TheRealSteveJudge 24-Apr-15 6:16am    
Exactly! 5*
Sergey Alexandrovich Kryukov 24-Apr-15 9:35am    
Thank you, Steve.
—SA
string currentDate = "04/28/2015";
DateTime.ParseExact(currentDate, "MM/dd/yyyy").ToString("dd/MM/yyyy")
/ravi
 
Share this answer
 
v2

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