Skip to content

Instantly share code, notes, and snippets.

@dave-jay
Created November 3, 2014 14:13
Show Gist options
  • Save dave-jay/0186c38061b1e04a50c7 to your computer and use it in GitHub Desktop.
Save dave-jay/0186c38061b1e04a50c7 to your computer and use it in GitHub Desktop.

Revisions

  1. dave-jay created this gist Nov 3, 2014.
    35 changes: 35 additions & 0 deletions _date_diff.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <?php

    function _dateDiff($date1, $date2) {
    $time = strtotime($date1);
    $time2 = strtotime($date2);

    $diff = $time - $time2;

    $return = array();
    $days = $diff / (60 * 60 * 24 );


    $whole = floor($days);
    $hours = intval(($days - $whole)*24);

    $return['days'] = intval($days);
    $return['hours'] = $hours;

    return $return;;

    }

    _dateDiff("2014-11-05 11:00:00", "2014-11-01 13:00:00"));

    # returns:
    /*
    ...Array
    (
    [days] => 3
    [hours] => 23
    )
    */


    ?>