[ACCEPTED]-TimeSpan using a nullable date-nullable
Accepted answer
To subtract two dates when zero, one or 4 both of them is nullable you just subtract them. The subtraction 3 operator does the right thing; there's no 2 need for you to write all the logic yourself 1 that is already in the subtraction operator.
TimeSpan? timeOnPlan = DateTime.Now - user.PlanStartDate;
return timeOnPlan == null ? 0 : timeOnPlan.Days / 7;
Try this:
weeksOnPlanSpan = DateTime.Now.Subtract(planStartDate.Value);
0
Cast the nullable datetime as a normal datetime.
If 2 you know it is not null, then the cast will 1 work fine.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.