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

  • Home
  • SEARCH
  • 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 7663911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:10:08+00:00 2026-05-31T14:10:08+00:00

I need to display a post time of the comment for a particular article

  • 0

I need to display a post time of the comment for a particular article or node. I need the post time of the comment in the format Time ago.

For example : 1 minute ago

Can there is any way to achieve the Time ago format display for comment display in drupal 7.

  • 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-31T14:10:09+00:00Added an answer on May 31, 2026 at 2:10 pm

    I think I remember there may be a native function that does this in D7 but have not found it. So meanwhile you could just have this function in a template:

    function ago($timestamp){
       $difference = time() - $timestamp;
       $periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");
       $lengths = array("60","60","24","7","4.35","12","10");
       for($j = 0; $difference >= $lengths[$j]; $j++)
       $difference /= $lengths[$j];
       $difference = round($difference);
       if($difference != 1) $periods[$j].= "s";
       $text = "$difference $periods[$j] ago";
       return $text;
      }
    

    Then, when you need to print a ‘time since’ type of date, for instance time since user has logged in:

       global $user;
       echo "Last login: ".ago($user->login);
    

    Hope that helps, good luck.

    PS – Consider posting upcoming questions on drupal.stackexchange.com your post will be targeted to many awesome Drupal devs there. Good-luck, happy coding.

    Update – There IS a native function in Drupal to format date intervals, it is called format_interval.

    Usage example:

     // Date since forum post was created
     format_interval(REQUEST_TIME - $variables['topic']->created) 
    

    Much simpler like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a post and i need to display how long ago it was
I have a similar problem to this post . I need to display up
I need to display all my post titles in the sidebar of my Wordpress
i am developing one application with map view i need display the weather depends
I need to display an error message on rejecting a drop in my application.
I need to display many pages of news in a site. Should I do
I need to display a variable-length message and allow the text to be selectable.
I need to display additional information, like a tooltip, but it's a lot of
I need to display the log entries from a database. Of course the log
I need to display 2d images in opengl using textures. The image dimensions are

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.