0

Difference between two dates includes both the dates
For example

$date1=date_create("2015-01-01");
$date2=date_create("2015-01-03");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");

Output :

+2 days 

But I need to get +3 days as output like from starting date to ending date

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
Iyappan Krish
  • 31
  • 1
  • 4
  • use : http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – Ishan Shah Oct 08 '15 at 07:26

2 Answers2

2

You can do something like as

$date1=date_create("2015-01-01");
$date2=date_create("2015-01-03")->modify("+1 day");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");

Output:

+3 days

Demo

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
0

Use the below code

<?php
$date1 = date_create("2015-01-01");
$date2 = date_create("2015-01-03");
date_add($date2,date_interval_create_from_date_string('1 day'));
$diff = date_diff($date1, $date2);
echo $diff->format("%R%a days");
?>
Kausha Mehta
  • 2,828
  • 2
  • 20
  • 31