Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: String reference not set to an instance of a String. Parameter name: s

Tags:

c#

asp.net

I am using this code to truncate datetime from my database into its year and time components. The variables YearOfRelease and Runtime contain datetime of the format "dd/MM/yyyy hh:mm:ss" It was working fine previously but its now giving the error:

String reference not set to an instance of a String. Parameter name: s

It could only be something wrong in the DateTime.ParseExact function, could anyone please let me know why 'null' is suddenly causing this problem when previously it was working perfectly?

    DateTime dt2 = new DateTime();


    dt = DateTime.ParseExact(YearOfRelease, "dd/MM/yyyy hh:mm:ss", null);

    Year = dt.Year.ToString();


    dt2 = DateTime.ParseExact(RunTime, "dd/MM/yyyy hh:mm:ss", null);
    string hour = dt2.Hour.ToString();
    string min = dt2.Minute.ToString();

    Time = hour + ":" + min;
like image 536
QPTR Avatar asked May 06 '11 03:05

QPTR


1 Answers

The first parameter of DateTime.ParseExact is a string parameter named 's'.

Therefore, it looks like YearOfRelease or RunTime is null in your program. Make sure those are set before you call DateTime.ParseExact.

like image 91
Brian Geihsler Avatar answered Oct 19 '22 10:10

Brian Geihsler