Please Covert this

K

Karunakararao

Hi ALL
this string object usi.RequestFilterRequestFromDate

iam doing like this
But it is giving error - "String was not recognized as a valid DateTime."

strDate =usi.RequestFilterRequestFromDate;
string val = DateTime.Parse(strDate).ToString("yyyy-MM-dd");

Thanks

Venu
 
J

John Mark Howell

What is the contents of usi.RequestFilterRequestFromDate? It is saying
that strDate is not a valid date. Remember, an empty string is not a valid
date.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi

From the error it seems that strDate is not a valid string date, where it's
coming from ? and how it looks like?

Cheers,
 
J

John Mark Howell

Here is code that works. As you can see, you can put the date string in
various formats:

String strDate = "05/01/1990";
string val = DateTime.Parse(strDate).ToString("yyyy-MM-dd");
MessageBox.Show(val);

strDate = "05-01-1990";
val = DateTime.Parse(strDate).ToString("yyyy-MM-dd");
MessageBox.Show(val);

strDate = "1990-05-01";
val = DateTime.Parse(strDate).ToString("yyyy-MM-dd");
MessageBox.Show(val);

strDate = "05-01-1990 12:30 PM";
val = DateTime.Parse(strDate).ToString("yyyy-MM-dd");
MessageBox.Show(val);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top