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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:42:30+00:00 2026-05-26T00:42:30+00:00

im having a problem converting time. for some reason it seems to be defaulting

  • 0

im having a problem converting time. for some reason it seems to be defaulting back to 1970 which i believe is unix default time. im using this code, when i run the program i get 42years instead of 2 years. what am i missing. please help
here is the code

<?php

  function convertime($ptime) {
        $etime = time() - $ptime;

        if($etime < 60) {
                return 'less than minute ag';
        }

        $a = array(12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute' //  1                       =>  'second'
                );

        foreach($a as $secs => $str) {
                $d = $etime / $secs;
                if($d >= 1) {
                        $r = round($d);
                        return $r . ' ' . $str . ($r > 1 ? 's' : '');
                }
        }
  }

?>

<?php

  $ctime = 2009-02-23 10:09:00 //time from mysql
        echo convertime($ctime);

?>
  • 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-26T00:42:30+00:00Added an answer on May 26, 2026 at 12:42 am

    Wrap strtotime() around your timestamp:

    $ctime = strtotime('2009-02-23 10:09:00'); //time from mysql
    

    http://codepad.org/HWQrLwBy

    You need to compare a timestamp to a timestamp.

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

Sidebar

Related Questions

I am having a problem converting a date/time string to an NSDate. The date
I am having a problem with converting the date and time to milliseconds. There
I'm having a problem converting my program from VS2005 to VS2008. When I run
I am having no problem converting a string to a byteArray of UTF-16 encoded
I'm having a bit of a problem with converting the result of a MySQL
I am having problems converting a string in the format yyyy-MM-ddZ using VB.net. For
I having a problem converting a string into the date format I need. An
I am having this trouble in converting the exiting time string into a new
I am having problem with IdTCPclient.connected function from Indy in Delphi. I am using
I'm having some problems with converting some JSON and I'm after some help. This

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.