Click here to Skip to main content
15,881,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
value for ava is {12/12/2015 12:00:00 AM}

What I have tried:

ateTime ava = Convert.ToDateTime(theRow.Cells[3].Text);
DateTime to = Convert.ToDateTime(theRow.Cells[4].Text);
Response.Redirect("UpdateLoanType.aspx?type=" + type+"&term="+term+"&rate="+rate+"&ava="+ava+"&to="+to);


DateTime nowed = DateTime.ParseExact(Request.QueryString["ava"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
Posted
Updated 6-Aug-16 0:21am

Follow the above 2 solutions or just change the format while you are passing it to the query string..

C#
string ava = Convert.ToDateTime(theRow.Cells[3].Text).ToString("dd/MM/yyyy");
            string to = Convert.ToDateTime(theRow.Cells[4].Text).ToString("dd/MM/yyyy");  


and this should work in the target page:
C#
DateTime nowed = DateTime.ParseExact(Request.QueryString["ava"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
 
Share this answer
 
Well your input string is
12/12/2015 12:00:00 AM

and your parse expression is
dd/MM/yyyy

so your expression doesn't match the input string.

Try this expression instead:
dd/MM/yyyy hh:mm:ss tt


[UPDATE]
DateTime does not have a specific format, it is kind of a placeholder for a date and time.
Only when you decide to present the date to a user, in e.g. a text box, will you give it a format.
For this you can use the methods:
- ToLongDateString()
- ToLongTimeString()
- ToShortDateString()
- ToShortTimeString()
- ToString()

ToString() will give you the most control of the format and you can avoid culture variations of the date on different computers, unless that is desired.
See Custom Date and Time Format Strings[^]

For your desired format it would be
C#
DateTime dt = DateTime.Now;
string s = dt.ToString("dd/MM/yyyy");

So please forget about storing a date in a specific format.
The only way to do that is to store it as a string, and that would not be the smartest of things.
 
Share this answer
 
v2
Comments
Member 12652110 6-Aug-16 6:15am    
but im trying to convert it into dd/mm/yyyy
George Jonsson 6-Aug-16 20:39pm    
See my updated answer.
Because the value doesn't exactly match the pattern you supply:
12/12/2015 12:00:00 AM
Does not match:
dd/MM/yyyy
It does match:
dd/MM/yyyy hh:mm:ss tt
 
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