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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With