When try to convert string value in date-time format some time string variable comes with null value at that time it throws exception invalid format of the sting.
e.g
string abc=//date vale
datetime dt=new datetime();
dt=DateTime.Parse(abc);
//if abc comes null it throws exception.
//I can check in this way
if(abc!=null)
{
dt=DateTime.Parse(abc);
}
Have a look at
DateTime.TryParse[MSDN].EDIT:
If you don’t want to duplicate this code, put it in a method, perhaps with a nullable return value: