Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:30:45+00:00 2026-06-01T16:30:45+00:00

I need help to display something like this. If you recognize, this our membership

  • 0

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));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:30:47+00:00Added an answer on June 1, 2026 at 4:30 pm

    You can use the DateDiff class of the Time Period Library for .NET library:

    // ----------------------------------------------------------------------
    public void DateDiffSample()
    {
      DateTime date1 = new DateTime( 2009, 11, 8, 7, 13, 59 );
      Console.WriteLine( "Date1: {0}", date1 );
      // > Date1: 08.11.2009 07:13:59
      DateTime date2 = new DateTime( 2011, 3, 20, 19, 55, 28 );
      Console.WriteLine( "Date2: {0}", date2 );
      // > Date2: 20.03.2011 19:55:28
    
      DateDiff dateDiff = new DateDiff( date1, date2 );
    
      // elapsed
      Console.WriteLine( "DateDiff.ElapsedYears: {0}", dateDiff.ElapsedYears );
      // > DateDiff.ElapsedYears: 1
      Console.WriteLine( "DateDiff.ElapsedMonths: {0}", dateDiff.ElapsedMonths );
      // > DateDiff.ElapsedMonths: 4
      Console.WriteLine( "DateDiff.ElapsedDays: {0}", dateDiff.ElapsedDays );
      // > DateDiff.ElapsedDays: 12
      Console.WriteLine( "DateDiff.ElapsedHours: {0}", dateDiff.ElapsedHours );
      // > DateDiff.ElapsedHours: 12
      Console.WriteLine( "DateDiff.ElapsedMinutes: {0}", dateDiff.ElapsedMinutes );
      // > DateDiff.ElapsedMinutes: 41
      Console.WriteLine( "DateDiff.ElapsedSeconds: {0}", dateDiff.ElapsedSeconds );
      // > DateDiff.ElapsedSeconds: 29
    } // DateDiffSample
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help assigning a mouseover event to display some icons that start out
could you help me with styling of ItemTemplate for listbox. I need to display
Need help writing a script downloads data from google insight using c# this is
need help in error in database pivot. i have table tamed table_score like below:
I need help finishing this statement. It is frustrating that two of the PHP
Been trying this for quite a while now and I need help. Basically I
i need a little help with a AR query. This is how my models
I need some help, is it possible to display fb or twitter share page
I am pretty sure that if I use something like this in css #list
I have 4 jquery radio buttons in my form something like this <form:radiobutton path=lcmoption

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.