Hi
I am getting error on below code
DateTime? ActualActionDate;
ltrlDays.Text = (DateTime.Now - Convert.ToDateTime(ActualActionDate)).Days.ToString();
Thanks
Hi
I am getting error on below code
DateTime? ActualActionDate;
ltrlDays.Text = (DateTime.Now - Convert.ToDateTime(ActualActionDate)).Days.ToString();
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mohamed Azarudeen ZPosted Jun 18, 2023, 1:49 PM
Hi ramco
To fix the error and avoid the null reference exception, you should check if
ActualActionDatehas a value before performing the calculation. Here's an updated version of your code:Tuhin PaulPosted Jun 18, 2023, 2:55 PM
Assign a valid DateTime value to the ActualActionDate variable before using it in the calculation. Make sure to replace (...) with the code that assigns a valid DateTime value to ActualActionDate. Then, we check if ActualActionDate is not null (ActualActionDate != null), and if it's not null, we calculate the difference in days between the current date and ActualActionDate using the .Value property.