• For lot of reasons (too long to explain in fact) I have several dates by post in the DB (add by myself).

    So post_date, post_datedead, post_datefuture, post_datepast. I have made functions in a plugin by copying template function “the_date()”. Everything works.

    My problem is I need to compare these dates, to know for example how much days there are between the 15/02/2005 and the 18/03/2005, and catch it in a variable…

    I have made some mysql functions like “the_datepast_mysql()”

    see :

    function the_datepast_mysql() {
    global $post;
    echo $post->post_datedebut;
    }

    It works. And another function to compare :

    see :

    function numberofdays($mmstart, $mmend) {

    $tDeb = explode(“-“, $mmstart);
    $tFin = explode(“-“, $mmend);

    $diff = mktime(0,0,0, $tFin[1], $tFin[2], $tFin[0]) –
    mktime(0,0,0, $tDeb[1], $tDeb[2], $tDeb[0]);

    return(($diff / 86400)+1);

    }

    But I can’t catch a result ! … ? I can’t understand why and it’s perhaps under my nose but I can’t understand why and it’s perhaps under my nose but I can’t understand why and it’s perhaps under my nose but I can’t understand why and it’s perhaps under my nose but I can’t understand why… horrible.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’re aware return doesn’t output anything, right?

    Thread Starter hapaxlegomen

    (@hapaxlegomen)

    Euh No. My only knowledge is to copy paste functions everywhere and try to make them work. So lot of things are chinese to me but some are understood.

    What must I do to make this give me my number of days ??
    (Thanks for help)

    return doesn’t output anything, it only returns the value. Replace return with echo. Oh, and you don’t need parenthesis either:

    echo ($diff / 86400)+1;

    And may I just suggest this plugin instead? You can see it in action on my blog.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Compare two dates’ is closed to new replies.