-1

How can I get the year, month week day, hour, minute, second interval on two dates on php?

For example:

date1 = 2015-9-24 date2 = 2015-12-25

Output:

3 months and 1 day left

Thanks guys.

Makudex
  • 1,042
  • 4
  • 15
  • 40
  • Please try to use Google before Stackoverflow. http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – Vincent Decaux Sep 25 '15 at 07:13
  • Check this out : http://stackoverflow.com/questions/4616746/how-extract-years-months-days-hours-minutes-seconds-from-a-mysql-date – Suyog Sep 25 '15 at 07:15

3 Answers3

1

Please try php diff

$date1 = new DateTime("2015-9-24");
$date2 = new DateTime("2015-12-25");
$interval = $date1->diff($date2);
echo "Result " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; 
echo "Result " . $interval->days . " days ";
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
1

Try this

$a1 = new DateTime('2015-9-24');
$a2 = new DateTime('2015-12-25');

$interval = $a2->diff($a1);

 $interval->format('%m months');
1

You are use PHP date_diff() Function

$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);