减去2日期时的错误值[关闭]

I get the wrong value when I subtract two dates. This is my code:

$date2=strtotime('01-08-2014');
$date1=strtotime('28-06-2014');
$diff=$date2-$date1;

Output:

$diff=-27

EDIT :

$date2 should be --> date('d/m/Y',strtotime('01-08-2014'));
$date1 should be --> date('d/m/Y',strtotime('28-06-2014'));

Can anyone solve my problem?

thanks

Should be

 $diff=$date2-$date;

to

   $diff=$date2-$date1;

Why not use DateTime::diff

$datetime1 = new DateTime('01-08-2014');
$datetime2 = new DateTime('28-06-2014');
$interval = $datetime1->diff($datetime2);

Try this:

<?php
$daylen = 60*60*24;

   $date1 = '2010-03-29';
   $date2 = '2009-07-16';

   echo (strtotime($date1)-strtotime($date2))/$daylen;

?>