Hướng dẫn dùng time diff trong PHP
How to calculate minute difference between two date-times in PHP? S.L. Barth 8,08971 gold badges50 silver badges63 bronze badges asked Dec 13, 2008 at 13:05 Tom SmykowskiTom Smykowski 24.8k52 gold badges155 silver badges227 bronze badges The answers above are for older versions of PHP. Use the DateTime class to do any date calculations now that PHP 5.3 is the norm. Eg.
$since_start is a DateInterval object. Note that the days property is available (because we used the diff method of the DateTime class to generate the DateInterval object). The above code will output: 1837 days total To get the total number of minutes:
This will output: 2645654 minutes Which is the actual number of minutes that has passed between the two dates. The DateTime class will take daylight saving (depending on timezone) into account where the "old way" won't. Read the manual about Date and Time http://www.php.net/manual/en/book.datetime.php answered Sep 12, 2012 at 7:11 17 Here is the answer:
answered Dec 13, 2008 at 13:36 user38526user38526 3,7532 gold badges14 silver badges2 bronze badges 4 Subtract the past most one from the future most one and divide by 60. Times are done in Unix format so they're just a big number showing the number of seconds from Noman 1,3902 gold badges17 silver badges38 bronze badges answered Dec 13, 2008 at 13:23 Có thể bạn quan tâmOliOli 231k62 gold badges216 silver badges294 bronze badges 3
answered Dec 13, 2008 at 15:49 TomTom 8,98229 gold badges129 silver badges226 bronze badges 3
Output:
answered Sep 12, 2019 at 14:10 0 It worked on my programs, i'am using
You get results what do you want. answered Jul 9, 2015 at 15:43 yussanyussan 2,2501 gold badge19 silver badges24 bronze badges 2 another way with timezone.
answered Dec 24, 2013 at 13:16 MuhammadMuhammad 3,0795 gold badges39 silver badges68 bronze badges 1 I wrote this function for one my blog site(difference between a past date and server's date). It will give you an output like this "49 seconds ago", "20 minutes ago", "21 hours ago" and so on I have used a function that would get me the difference between the date passed and the server's date.
Save it as a file suppose "date.php". Call the function from another page like this
Of course you can modify the function to pass two values. RiggsFolly 90.6k20 gold badges101 silver badges144 bronze badges answered Jun 7, 2014 at 19:21 0
answered May 25, 2021 at 15:26 Şafak GezerŞafak Gezer 3,7673 gold badges42 silver badges48 bronze badges I think this will help you
answered Oct 31, 2014 at 5:26 2 This is how I displayed "xx times ago" in php > 5.2 .. here is more info on DateTime object
RiggsFolly 90.6k20 gold badges101 silver badges144 bronze badges answered Mar 27, 2014 at 4:11 hriziyahriziya 1,0461 gold badge20 silver badges40 bronze badges
answered Jan 28, 2015 at 7:05 VeerendraVeerendra 2,5602 gold badges21 silver badges39 bronze badges A more universal version that returns result in days, hours, minutes or seconds including fractions/decimals:
answered Jun 1, 2017 at 22:19 besimplebesimple 4441 gold badge7 silver badges12 bronze badges 1 Subtract the times and divide by 60. Here is an example which calculate elapsed time from
answered Oct 30, 2019 at 14:54 My solution to find the difference between two dates is here. With this function you can find differences like seconds, minutes, hours, days, years and months.
You can develop this function. I tested and works for me. DateInterval object output is here:
Function Usage: $date = the past date, $diff = type eg: "minutes", "days", "seconds"
Good Luck. answered Mar 24, 2019 at 2:52 Ali HanAli Han 4495 silver badges10 bronze badges
For detailed format specifiers, visit the link. answered Nov 1, 2020 at 11:42 snrsnr 16.7k2 gold badges67 silver badges90 bronze badges Another simple way to calculate the difference in minutes. Please note this is a sample for calculating within a 1-year range. for more details click here
answered Feb 13, 2021 at 20:20 This will help....
answered Jan 16, 2018 at 4:57 GYaNGYaN 2,3254 gold badges18 silver badges38 bronze badges 1 I found so many solution but I never got correct solution. But i have created some code to find minutes please check it.
It gives output in hours and minutes for example 01 hour 02 minutes like 01:02 answered Jun 5, 2019 at 9:45 Here is a simple one-liner:
answered Nov 30, 2021 at 17:11 nimrodnimrod 5,48528 gold badges83 silver badges147 bronze badges try this
answered May 8, 2021 at 8:43 Not the answer you're looking for? Browse other questions tagged php date time minute or ask your own question. |