0

hey i want to get difference between two dates like

date1= 2014-03-3 
date2= 2014-03-4 

when i sub this two date like date2-date1 then it should give us 2

ie. i just want to add new day after 12 am at night..how is it possible using php function?

I tried some code like

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

but it does not work

please help

Prix
  • 19,417
  • 15
  • 73
  • 132
Brett
  • 431
  • 2
  • 10
  • 26

4 Answers4

0

Try

$datetime1 = new DateTime('2014-03-3');
$datetime2 = new DateTime('2014-03-4');
$interval = $datetime1->diff($datetime2);
$dayCount = $interval->format('%a');
echo $dayCount;

See demo here

Nouphal.M
  • 6,304
  • 1
  • 17
  • 28
0

If you are interested just in numeric value you can do:

$diff = strtotime($date2) - strtotime($date1);
Rafał Wrzeszcz
  • 1,996
  • 4
  • 23
  • 45
0

This could help you

   $date1 = new DateTime("2013-03-15");
   $date2 = new DateTime("2013-12-12");
   $interval = $date1->diff($date2);
   echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; 
Kokil
  • 560
  • 1
  • 5
  • 16
0

Check this if it helps you

$datetime1 = strtotime('2014-03-3');
$datetime2 = strtotime('2014-03-4');
$timeDiff = $datetime2-$datetime1;
$dayCount=floor($timeDiff/(60*60*24)); //calculate day count.
echo $dayCount;

it will give you count 1, and if you provide the date with time then also it will work.

Deepak Goswami
  • 2,030
  • 1
  • 16
  • 22