Hi
C#
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Jun 18, 2023, 10:35 PM EDT
Where is the value assigned to StuckDate in that code? Can you tell us where it is assigned a value?
Ramco RamcoRank #462 · 5.4K reputationPosted Jun 18, 2023, 10:51 PM EDT
Hi Sam
foreach (View_LeadDetail colum in objResult) { if (rowctr == 1) { ActualActionDate = Convert.ToDateTime(colum.ActualActionDate); StuckDate = Convert.ToDateTime(colum.ActualActionDate); } if (colum.ActionTypeID != Convert.ToInt32(hdfActionTypeId.Value)) { ltrlDays.Text = (DateTime.Now - StuckDate).Days.ToString(); break; } else { StuckDate = Convert.ToDateTime(colum.ActualActionDate); } rowctr++; }Thanks
Jignesh KumarRank #91 · 22.9K reputationPosted Jun 18, 2023, 11:44 PM EDT
Hi Ramco,
you are assigning stuckDate variable in if condition and trying to use in other block.
foreach (View_LeadDetail colum in objResult) { StuckDate = Convert.ToDateTime(colum.ActualActionDate); if (rowctr == 1) { ActualActionDate = Convert.ToDateTime(colum.ActualActionDate); } if (colum.ActionTypeID != Convert.ToInt32(hdfActionTypeId.Value)) { ltrlDays.Text = (DateTime.Now - StuckDate).Days.ToString(); break; } rowctr++; }Ramco RamcoRank #462 · 5.4K reputationPosted Jun 18, 2023, 11:55 PM EDT
Hi Jignesh
I have defined it before loop
DateTime StuckDate;
Thanks
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Jun 19, 2023, 3:35 AM EDT
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.