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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:13:39+00:00 2026-05-13T10:13:39+00:00

here is my php code….. <?php function nicetime($date) { if(empty($date)) { return No date

  • 0

here is my php code…..

<?php
function nicetime($date)
{
    if(empty($date)) {
        return "No date provided";
    }

    $periods         = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
    $lengths         = array("60","60","24","7","4.35","12","10");

    $now             = time();
    $unix_date  = strtotime($date);

       // check validity of date
    if(empty($unix_date)) {    
        return "Incorrect Date";
    }

    // is it future date or past date
    if($now > $unix_date) {    
        $difference     = $now - $unix_date;
        $tense         = "ago";

    } else {
        $difference     = $unix_date - $now;
        $tense         = "ago";
    }

    for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
        $difference /= $lengths[$j];
    }

    $difference = round($difference);

    if($difference != 1) {
        $periods[$j].= "s";
    }

    return "$difference $periods[$j] {$tense}";
}
?>

but it is not showing the time correctly….and if any current time is given to it is showing 25-35 seconds ago and so on….but i want to make a time difference funtion like digg.com in a format like 2 Mints AND 3 Sec ago… how can i do that

  • 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-13T10:13:39+00:00Added an answer on May 13, 2026 at 10:13 am

    Try it to do with the other way – at the beginning multiply all $lengths values (i.e. $multiplied).
    1. Divide $difference with that value.
    2. If >= 1 then you have a solution.
    Else divide $multiplied with the array_pop($lengths) value. Go to 2.
    3. You have the solution.

    I think it would be it.

    BTW – $tense is always "ago".

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • 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 I think that showing UITextView is ok. Moreover it seems… May 16, 2026 at 4:17 pm
  • Editorial Team
    Editorial Team added an answer Global Weather SOAP Webservice API Using PHP (with the SOAP… May 16, 2026 at 4:17 pm
  • Editorial Team
    Editorial Team added an answer I don't really know how it works, but the awesome… May 16, 2026 at 4:16 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

Related Questions

I am in a predicament here. My PHP code used to work but since
I want to make a multidimensional array in php. Here is what i have
Here is my PHP code: echo '<br />1. '.$w_time_no; echo '<br />2. '.strtotime($w_time_no); echo
I have a very similar setup to the person here: PHP Background Processes i.e
I'm testing a PHP mail form, a very barebones one, found here : <?php
Is it possible to upload files with PHP and SOAP? Here is the PHP
I need help sorting [Time] data from in this array in php. For a
I have html file with php code in it. It contains code to connect
Hey everyone... I'm not too familiar with PHP... but I have PHP code that
I'm no php expert (a mere beginner) but need some help! After hours searching

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.