![]() So we have successfully calculated the difference between two times or dates. The output will be something like you can see below depending upon the current time: 1 year 0 month 12 days 23 hour 28 minute 22 second Now if we want to get the time difference between current time and a previous time, then we just have to put the current DateTime object “new DateTime()” just like below: $time = new DateTime(' 18:16:25') Send SMS to Phone Number using Twilio in PHP.You can also print second, minutes, hours, day, month and year separately just by calling like methods from the DateTime class: echo $timediff->s."" The return value more specifically represents the clock-time interval to apply to the original object ( this or originObject) to arrive at the targetObject. The above PHP code will print the result that we can see below: 1 year 11 month 30 days 17 hour 20 minute 3 second absolute Should the interval be forced to be positive Return Values The DateInterval object represents the difference between the two dates. PHP already has the in-built DateTime class that can do it.īelow is an example where we have taken two date time string and showing it: $time1 = new DateTime(' 18:16:25') Įcho $timediff->format('%y year %m month %d days %h hour %i minute %s second')."" Getting the difference between two times is a quite easy task. now I am going to see the easiest way of getting the time difference in PHP. We will be using the built-in function datediff () to get the time difference in minutes. In that case, also, it is actually calculating the time difference. ![]() You may notice on social media network like Facebook shows a post published “1 hour ago” or “2 minutes ago” or something like that. Today in this post, we are going to see how to calculate and then get the time difference between two times in PHP.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |