code for compare two dates in php

It is for static page, dynamic page, website, SEO, performance and other web development discussion
Joshi jahanvi

code for compare two dates in php

Postby Joshi jahanvi » Thu Sep 11, 2014 3:59 pm

How can we know the number of days between two given dates using PHP?


Guest

Re: code for compare two dates in php

Postby Guest » Wed Oct 08, 2014 1:39 pm

Below code may help you.

Code: Select all

$datetime1 = new DateTime("2010-06-20");

$datetime2 = new DateTime("2011-06-22");

$difference = $datetime1->diff($datetime2);

echo 'Difference: '.$difference->y.' years, '
                   .$difference->m.' months, '
                   .$difference->d.' days';

print_r($difference);


Result as below:

Code: Select all

Difference: 1 years, 0 months, 2 days
    [days] => 367


Return to “PHP, HTML, MYSQL and Web Hosting”

Who is online

Users browsing this forum: No registered users and 1 guest