Hi
DateTime StuckDate;
ltrlDays.Text = (DateTime.Now - StuckDate).Days.ToString();
Thanks
Hi
DateTime StuckDate;
ltrlDays.Text = (DateTime.Now - StuckDate).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.
Brahma Prakash ShuklaPosted Jun 19, 2023, 7:35 AM
The error message you're encountering is because you're using an uninitialized variable,
StuckDate, in your code. Before subtractingDateTime.NowfromStuckDate, you need to assign a value toStuckDate.Here's an example of how you can fix the error:
DateTime StuckDate = new DateTime(2023, 6, 15); // Replace with your desired date ltrlDays.Text = (DateTime.Now - StuckDate).Days.ToString();In the above example, I've initialized
StuckDatewith a specific date (new DateTime(2023, 6, 15)). You should replace it with your desired date. By providing a valid value toStuckDate, you can perform the subtraction operation and retrieve the number of days using theDaysproperty.After assigning a value to
StuckDate, the expression(DateTime.Now - StuckDate).Dayswill give you the number of days between the current date and theStuckDate. TheToString()method converts the result to a string, which can be assigned to theltrlDays.Textproperty or used in any other way you require.Ramco RamcoPosted Jun 19, 2023, 3:55 AM
Hi Jignesh
I have defined it before loop
DateTime StuckDate;
Thanks
Jignesh KumarPosted Jun 19, 2023, 3:44 AM
Hi Ramco,
you are assigning stuckDate variable in if condition and trying to use in other block.
Ramco RamcoPosted Jun 19, 2023, 2:51 AM
Hi Sam
Thanks
Sam HobbsPosted Jun 19, 2023, 2:35 AM
Where is the value assigned to StuckDate in that code? Can you tell us where it is assigned a value?