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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:17:08+00:00 2026-05-27T22:17:08+00:00

All, I have the following PHP code to determine how many years apart two

  • 0

All,
I have the following PHP code to determine how many years apart two dates are on my WordPress page:

<?php
$date1 = new DateTime("2003-03-24");
$current_date = new DateTime(date("Y-m-d"));
$interval = $date1->diff($current_date);
echo $interval->y;
?>

I installed the Exec-PHP plugin for WordPress to display this properly. However when I try and display my page I get the following error:

Fatal error: Call to undefined method DateTime::diff() in
/home/person/test.website.com/wp-content/plugins/exec-php/includes/runtime.php(42)
: eval()’d code on line 7

How can I get this to work properly? Thanks!

  • 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-27T22:17:09+00:00Added an answer on May 27, 2026 at 10:17 pm

    I remember this question a while back: How to calculate the difference between two dates using PHP?

    With some small adjustments it looks like this:

    function convert_number($number) { 
        $Gn = floor($number / 1000000);  /* Millions (giga) */ 
        $number -= $Gn * 1000000; 
        $kn = floor($number / 1000);     /* Thousands (kilo) */ 
        $number -= $kn * 1000; 
        $Hn = floor($number / 100);      /* Hundreds (hecto) */ 
        $number -= $Hn * 100; 
        $Dn = floor($number / 10);       /* Tens (deca) */ 
        $n = $number % 10;               /* Ones */ 
    
        $res = ""; 
    
        if ($Gn)
            $res .= convert_number($Gn) . " Million"; 
        if ($kn)    { 
            $res .= (empty($res) ? "" : " ") . 
            convert_number($kn) . " Thousand"; 
        } 
    
        if ($Hn) { 
            $res .= (empty($res) ? "" : " ") . 
            convert_number($Hn) . " Hundred"; 
        } 
    
        $ones = array("", "One", "Two", "Three", "Four", "Five", "Six","Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen","Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen","Nineteen"); 
        $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty","Seventy", "Eigthy", "Ninety"); 
    
        if ($Dn || $n)  { 
            if (!empty($res))
                $res .= " and "; 
    
            if ($Dn < 2) 
            $res .= $ones[$Dn * 10 + $n]; 
            else { 
                $res .= $tens[$Dn]; 
    
                if ($n) 
    
                $res .= "-" . $ones[$n]; 
            } 
        } 
    
        if (empty($res)) 
            $res = "zero"; 
    
        return $res; 
    } 
    
    function yearsFromNow ($date) {
        return convert_number(floor(abs(strtotime($date) - strtotime(date("Y-m-d"))) / (365*60*60*24)));
    }
    
    echo yearsFromNow("2007-03-24");
    echo yearsFromNow("2009-06-26");
    

    Output:

    4
    2
    

    Number to letters function modified from this site: http://www.phpro.org/examples/Convert-Numbers-to-Words.html

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

Sidebar

Related Questions

In a php page I have following code: if($_REQUEST['c']!=) // I get error on
I have the following code to zip all the files and then save it
I have the following Regex to match all link tags on a page generated
I have the following php code: <?php session_start(); .... $result=$db->query($query); $row=$result->fetch_assoc(); $_SESSION['id']=$row['id']; header('Location: http://www.blabla.com/successLoginPage.php');
I have the following html generated through my PHP code. What I want to
I have the following code in controllers/list.php: <?php class List extends Controller { function
I have the following PHP code to display my tag cloud. It seems if
I've have the following (PHP) code that traverses an entire DOM document to get
I have the following code in php, when i execute it: <pre> <?php $input
I have the following PHP code which is attempting to check for password complexity

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.