count days between two dates

August 11, 2008


    //function that will count days
    function countdays($date1, $date2){
        $days = abs(strtotime($date1)-strtotime($date2)) / 86400;
        return $days;
    }

    //lets assign values
    $date1 = '2008-08-17';
    $date2 = '2008-08-12';
    echo countdays($date1, $date2); //executes our function

2 Responses to “count days between two dates”

  1. baha Says:

    by the way, there is a typo in your code:
    echo countdays($date1, date2); //executes our function

    date2 should be $date2


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.