I need help to display something like this. If you recognize, this our membership duration of Stack Overflow account.
member for 2 years, 3 months
I need a slight modification in the same. My conditions and display format are as follows:
Conditions Display Format
1. Below 7 days -> Days (5 days)
2. 7 -30 days -> Weeks, days ( 2 Weeks, 3 Days) in case of 17 days.
3. 30 - 365 -> Months, Weeks, Days (4Months, 2Weeks, 2Days) in case of 136 days
3. 365 or grter -> Years, Months only (2years, 3 Months)
What I did:
I am using Timespan to get the date difference. But I am not satisfied with my output. I have a member whose registration's going to 2 months old after 2-3 days, but still its showing 1 month ago. Here is my code:
TimeSpan ts = DateTime.Now - Convert.ToDateTime(company.RegistrationDate);
if (ts.Days > 365)
membersince.InnerText = string.Format("{0} years", (ts.Days / 365));
else if (ts.Days < 30)
membersince.InnerText = string.Format("{0} days", ts.Days);
else if(ts.Days > 30)
membersince.InnerText = string.Format("{0} months", (ts.Days/30));