Count Days Between Two Dates in php

<div class="line number1 index0 alt2">

function getTotalDays($fromDate,$toDate,$addLastDay = false){
    $date1 = new DateTime($from);
    $date2 = new DateTime($to);
    if($addLastDay){
        $date2-&gt;add(new DateInterval('P1D'));
    }
    return $date1 -&gt; diff($date2)-&gt;days;
}
echo getTotalDays('2011-04-11','2011-04-15');
//4
echo getTotalDays('2011-04-11','2011-04-15',true);
//5


</div>
Advertisements

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 )

Google+ photo

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

Connecting to %s