php - Why is DateTime:diff() off by one minute? -
I am using the DateTime :: diff () function, to resize it as soon as 10 minutes difference For some reason minute difference is closed by one
For example if I want to get the difference between 11:20 and 11:30 then it will save 9 minutes instead of 10.
In addition to this it is only true when "now and" If I am entering "11:20" in the
$ date;
Then it will show a 10 minute difference.
Here is an example of the code I wrote.
$ expiry_time = "11:30:00"; $ Date = new date time ("now", new datetime zone ("America / New York")); $ Time_now = $ date- & gt; Format ("H: I: S"); Copy $ time_now "& lt; br & gt;"; $ Time_remaining = $ date- & gt; Diff (new date time ($ end_time, new datetime time zone ("America / New York")); $ Min = $ time_remaining-> I;
As I said in the first comment, check:
Then, depending on the priority of your goal, take it into account (like: > = 30
?).
Comments
Post a Comment