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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:14:26+00:00 2026-05-15T15:14:26+00:00

So basically, I’m currently selecting a Timestamp from my MySQL database. In the database,

  • 0

So basically, I’m currently selecting a Timestamp from my MySQL database. In the database, the timestamp looks like so:

2010-06-30 12:36:08

Obviously for a webapp, that’s not very attractive for users to view. So, using some CodeIgniter functions, I made it look a bit nicer.

<h4 class="timestamp">
    <?php // Quickly calculate the timespan
    $post_date = mysql_to_unix($row->date);
    $now = time();
    echo timespan($post_date, $now);?> ago
</h4>

If you don’t do CodeIgniter, everything’s standard PHP except for echo timespan(). CodeIgniter just echoes it as an ‘English’ timespan. So, an example output would be:

2 Months, 4 Weeks, 5 Hours, 20 Minutes ago

That’s all well and good, but, I want to make it seem nicer still… there are too many commas and its all a tad too long (I know, I’m picky…). What I’d like is:

  1. If the timespan is less than a day old, the output should be 7 hours, 33 minutes ago
  2. If the timespan is less than a week old, the output should be 4 days ago
  3. If the timespan is less than a month old, the output should be 2 weeks, 6 days ago
  4. If the timespan is over a month old, the output should be 4 months ago
  5. In the eventual case of the timespan being over a year old, the output should be Over a year ago

As you can see, I’m currently using a CodeIgniter function to simplify this – but if there’s any native PHP function that can do what I want it to, that’ll be awesome.

Thanks for your help!

Jack

  • 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-15T15:14:27+00:00Added an answer on May 15, 2026 at 3:14 pm

    This is best done on the client side in the presentation layer. Here is a JS solution:

    Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. “4 minutes ago” or “about 1 day ago”).

    Timeago will turn all abbr elements with a class of timeago and an ISO 8601 timestamp in the title:

    <abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
    

    into something like this:

    <abbr class="timeago" title="July 17, 2008">about a year ago</abbr>
    

    To convert the date into the ISO 8601 format you can do something like this:

    <?= date("c", $post_date) ?>
    

    Examples:

    You opened this page less than a
    minute ago. (This will update every
    minute. Wait for it.)

    This page was last modified 11 days
    ago.

    Ryan was born 31 years ago.

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

Sidebar

Ask A Question

Stats

  • Questions 446k
  • Answers 446k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Depends on your needs. Either way works, but I generally… May 15, 2026 at 7:23 pm
  • Editorial Team
    Editorial Team added an answer Yes, create a Windows service which wakes up every x… May 15, 2026 at 7:23 pm
  • Editorial Team
    Editorial Team added an answer * indicates a pointer, because you can access its contents… May 15, 2026 at 7:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.