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 854215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:53:20+00:00 2026-05-15T07:53:20+00:00

Possible Duplicate: How do I calculate relative time? I am searching for a custom

  • 0

Possible Duplicate:
How do I calculate relative time?

I am searching for a custom control for asp.net, which helps display user friendly dates, like instead of article date:

(2-april-2010)

it displays

(2 months old)

I am unable to find it on google, please can any one suggest links, custom controls, articles for the same.

Thank you.

  • 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-05-15T07:53:21+00:00Added an answer on May 15, 2026 at 7:53 am

    Try this (this is a datetime extension). So usage is:

    var date = new DateTime.Now;
    
    string formattedDate = date.ToReadableTimespan();
    
    
    public static string ToReadableTimespan(this DateTime d)
                {
                    // 1.
                    // Get time span elapsed since the date.
                    TimeSpan s = DateTime.Now.Subtract(d);
    
                    // 2.
                    // Get total number of days elapsed.
                    int dayDiff = (int)s.TotalDays;
    
                    // 3.
                    // Get total number of seconds elapsed.
                    int secDiff = (int)s.TotalSeconds;
    
                    // 4.
                    // Don't allow out of range values.
                    if (dayDiff < 0 || dayDiff >= 31)
                    {
                        return null;
                    }
    
                    // 5.
                    // Handle same-day times.
                    if (dayDiff == 0)
                    {
                        // A.
                        // Less than one minute ago.
                        if (secDiff < 60)
                        {
                            return "just now";
                        }
                        // B.
                        // Less than 2 minutes ago.
                        if (secDiff < 120)
                        {
                            return "1 minute ago";
                        }
                        // C.
                        // Less than one hour ago.
                        if (secDiff < 3600)
                        {
                            return string.Format("{0} minutes ago",
                                Math.Floor((double)secDiff / 60));
                        }
                        // D.
                        // Less than 2 hours ago.
                        if (secDiff < 7200)
                        {
                            return "1 hour ago";
                        }
                        // E.
                        // Less than one day ago.
                        if (secDiff < 86400)
                        {
                            return string.Format("{0} hours ago",
                                Math.Floor((double)secDiff / 3600));
                        }
                    }
                    // 6.
                    // Handle previous days.
                    if (dayDiff == 1)
                    {
                        return "yesterday";
                    }
                    if (dayDiff < 7)
                    {
                        return string.Format("{0} days ago",
                            dayDiff);
                    }
                    if (dayDiff < 31)
                    {
                        return string.Format("{0} weeks ago",
                            Math.Ceiling((double)dayDiff / 7));
                    }
                    return null;
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I calculate relative time? I want to convert Date Value
Possible Duplicate: How do I calculate relative time? Is there anything similar to rails'
Possible Duplicate: How do I calculate relative time? I did stumble upon a nice
Possible Duplicate: How do I calculate relative time? I want to format dates on
Possible Duplicate: Function to Calculate Median in Sql Server Goal: Display the value of
Possible Duplicate: how to calculate the current speed and average speed of user travelling
Possible Duplicate: How to calculate relative path between 2 directory path? I need to
Possible Duplicate: Calculate week of month in .NET I need to calculate the week
Possible Duplicate: Calculate date/time difference in java how would a future date such as
Possible Duplicate: Calculate age in JavaScript In some point of my JS code I

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.