I would to calculate between two given dates the TimeSpan, counting down to 0 days. I have the following code:
partial void mExpiration_Compute(ref string result)
{
DateTime a = mExpiryDate.AddMonths(-1);
DateTime b = mExpiryDate;
TimeSpan ts = b.Subtract(a);
// Difference in days.
int c = ts.Days;
result = Convert.ToString(c);
}
If the TimeSpan is currently 31, then I would like the reducing balance time. Example: "You have 24 days to expiry date." Note: The balance reducing is ( 31, 30, .., 24 etc)
How do I count down between given dates.
Your function never returns anything other 31, because you are calculating the days remaining exactly one month relative to the expiry date (i.e. the function always calculates the days between
02/09/215and02/08/2015, thus always returns a constant value).Assuming your
mExpiryDateis persisted and does not change, this is how I would calculate the days remaining (relative to the current date):