-4

how to calculate the minute difference for 2 values:-

strtotime("-15 minutes"); 
strtotime("now");

i have used below code:-

$diff = floor(strtotime("now") - strtotime("-15 minutes")/3600 );

but it gives 5 days of difference. please guide me where I am wrong.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
Piya Sharma
  • 19
  • 2
  • 9

1 Answers1

1

First of all you are getting hour diff with division to 3600. 15 minutes evaluates to 0 when floored. Also you are only dividing the second variable not the first with those brackets. this should work:

$diff=floor((strtotime("now") - strtotime("-15 minutes"))/60);
echo $diff;// outputs 15
Volkan Ulukut
  • 4,230
  • 1
  • 20
  • 38