-1

I am trying to calculate the difference between to times in minutes and everytime i try it shows the incorrect time. I am not sure what I am doing wrong here. Below is my code. Any help would be really appreciate it.

$time_now = new DateTime("now",new DateTimeZone("America/New_York"));
$future_order_time = new DateTime("7:00 pm",new DateTimeZone("America/New_York"));

$interval = $time_now->diff($future_order_time);

echo $interval->format("%i");
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
json2021
  • 2,146
  • 2
  • 14
  • 28
  • 2
    https://stackoverflow.com/a/12382882/5180509 This should answer your question. – JazZ Aug 23 '21 at 21:14
  • 1
    Does this answer your question? [How to get time difference in minutes in PHP](https://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php) – jspit Aug 24 '21 at 06:48

1 Answers1

1

DateTime::diff returns the difference in days, hours, minutes (and seconds, microseconds). You have to take into account the days and hours in your bill.

$diffMinutes = ($interval->days * 24 + $interval->h) * 60 + $interval->i;
jspit
  • 7,276
  • 1
  • 9
  • 17