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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:57:57+00:00 2026-05-26T13:57:57+00:00

Why the following code: function dDiff($start, $end = false) { if(!$end) { $end =

  • 0

Why the following code:

function dDiff($start, $end = false)
{
    if(!$end)
    {
        $end = time();
    }

    if(!is_numeric($start) || !is_numeric($end))
    {
        return false;
    }

    $start  = date('Y-m-d H:i:s',$start); 
    $end    = date('Y-m-d H:i:s',$end); 
    $d_start    = new DateTime($start);
    $d_end      = new DateTime($end);
    $diff = $d_start->diff($d_end);

    return array(
        'year' => $diff->format('%y'),
        'month' => $diff->format('%m'),
        'day' => $diff->format('%d'),
        'hour' => $diff->format('%h'),
        'min' => $diff->format('%i'),
        'sec' => $diff->format('%s')
    );
}

produce that error :

Fatal error: Call to undefined method DateTime::diff()
  • 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-26T13:57:58+00:00Added an answer on May 26, 2026 at 1:57 pm

    You get the error because the diff() function does not exists on the DateTime object. That’s the case with PHP versions below 5.3 In the manual that’s written as

    (PHP 5 >= 5.3.0)

    on top of each function page.

    You either need to make PHP 5.3 a requirement for your plugin and/or switch to an alternative routine for that part. See How to calculate the difference between two dates using PHP?.

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

Sidebar

Related Questions

I have the following code: function loadTweets() { $('#mainForm').submit(function(){ return false; }); $('#send').click(function(){ $('#tweets').html('');
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {
In the following code: function a(){ echo 'a'; return array(1,2,3,4); } foreach(a() as $t){
Given is the following code: function two() { return success; } function one() {
I have the following code: function lower_than_10($i) { return ($i < 10); } that
Using the following code: function mymodule_menu_alter(&$items) { if (isset($items['node/add/page'])) { $items['node/add/page']['access arguments'] = FALSE;
I have the following code: function convert($contents, $name){ echo($link); //prints nothing $pdf=new HTML2FPDF(); $pdf->AddPage();
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()
I am creating several image dynamically using the following code: function refresh_gallery(galleryidentifier, albumid) {

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.