Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a require of of setting date in format of dd\/mm\/yyyy i tried

string date = dy + @"\" + "/" + mn + @"\" + "/" + yy;

but during debug where i assign value becomes dd\\/mm\\/yyyy i also tried

string test = date.Replace("\\",@"\");

it changes value in output but i have to assign value on server side and use futher for posting....please help
Posted
Comments
Tomas Takac 21-May-15 3:37am    
Yes, debugger displays strings that way. But it doesn't mean there are two backslashes. Did you try to print the string to console? It will be correct.
Naveen Singh 21-May-15 3:42am    
C# donot allow to put single \ when i take output its is single \ but when i assign value on server side it reamains "dd\\/mm\\/yyyy" i just want to convert this into -> dd\/mm\/yyyy i dnnt have to print i just have to assign value on server side and then post not have to print.
Philippe Mori 21-May-15 12:53pm    
Last replace in your question does notmake sense as you remplace one backslash by one backslash!

As mentionned by other, the debugger shows \\ for backslash but you can open the text visualizer which write the text as it. It is then easier to figure out the final string if there is a lot of backslashes.

By the way, it is hard to understand your question as we cannot make sense of it as the text should be what you say it would.

Date has no special Format - it isn't a string.
If you want a string, which Displays your Date in a special way you could use the toString-Command of Date. Here you could build up your Output-String as you want.
C#
myString = myDate.toString("MMMM mm.yyyy") ;
... or what you want.
Refer the decription of the toString-Placeholders ...
 
Share this answer
 
Comments
Naveen Singh 21-May-15 3:42am    
C# donot allow to put single \ when i take output its is single \ but when i assign value on server side it reamains "dd\\/mm\\/yyyy" i just want to convert this into -> dd\/mm\/yyyy i dnnt have to print i just have to assign value on server side and then post not have to print.
What are you trying to do with the resulting string? The following code should work:
C#
string date = dy + "\\/" + mn + "\\/" + yy;

Alternatively if your values are already in a DateTime object you could just use:
C#
string date = sDate.ToString("dd\\\\/MM\\\\/yy");

// or

string date = sDate.ToString(@"dd\\/MM\\/yy");
 
Share this answer
 
v6
Comments
Naveen Singh 21-May-15 3:59am    
Hi Richard Thanks for yours reply i tried all this but c# donot allow \ this because it is a escape character so while when i try to format in yours manner its shows error.
Richard MacCutchan 21-May-15 4:49am    
Sorry, bad formatting above, now fixed. You need to use a double backslash in each position.
Naveen Singh 21-May-15 5:15am    
HI Richard thanks for yours response but still iam getting 19\\//5\\//1990 this format value.my code is
DateTime datevalue = Convert.ToDateTime(sDate.ToString());

String dy = datevalue.Day.ToString();
String mn = datevalue.Month.ToString();
String yy = datevalue.Year.ToString();
string date = dy + "\\" + "//" + mn + "\\" + "//" + yy;
Richard MacCutchan 21-May-15 5:32am    
Yes, my apologies I should remember that the ToString method interprets the backslashes so you need either the '@' prefix, or four backslashes. Use the second or third version as above; there is no point in extracting the day, month and year and converting them to strings when ToString does it all for you.
Naveen Singh 21-May-15 6:58am    
doesnt work for me :(

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