I retrive data from web service. My date is in the format 20/6/2006 0:00. When I try to format date with the following code it gives me above error.
the code is
String.Format("{0:MMMM d, yyyy}",Date.Parse(_landcorReport.vrValuationDate))
please help me
please guys can any one help me?Hi,
Make sure you are getting valid date in _landcorReport.vrValuationDate. Try using TryParse with an out variable of DateTime type, and then try to format it.
DateTime dt;
bool result = DateTime.TryParse(_landcorReport.vrValuationDate.ToString(), out dt);
Thanks,
unless you are doing Visual J#, you should be usingDateTime.Parse instead
String.Format ( "{0:MMMM d, yyyy}",DateTime.Parse ( _landcorReport.vrValuationDate ) )
that should work assuming of course that _landcorReport.vrValuationDate returns a string that is convertible to a valid date
ReyN:
unless you are doing Visual J#, you should be usingDateTime.Parse instead
String.Format ( "{0:MMMM d, yyyy}",DateTime.Parse ( _landcorReport.vrValuationDate ) )
that should work assuming of course that _landcorReport.vrValuationDate returns a string that is convertible to a valid date
If the input string cannot be converted to DateTime, an exception will be thrown. If you are not sure whether the input string can be converted to datetime, use the TryParse, as this method tries to parse only if the input string is valid and gives you the result if succeeded into the out variable. If you are not using TryParse, you need to use a try {} catch {} block to handle the exception.
Thanks
This method is available in .Net 2.0 while I'm working in .Net 1.1
Hi
Check if the value of_landcorReport.vrValuationDate is a valid date, or use your statement in try catch block
THanks
0 comments:
Post a Comment