arikflorida Posted February 5, 2007 Share Posted February 5, 2007 i wold like to know how to calculate, or u have a script to check how many times hour (for exmple 20:00:00) pass between and time. like between: 2/04/07 12:00:00 to 2/05/07 22:00:00 its 2 times. thanks Quote Link to comment https://forums.phpfreaks.com/topic/37153-check-how-many-times-some-houer-pass-between-2-diff-dates/ Share on other sites More sharing options...
Orio Posted February 5, 2007 Share Posted February 5, 2007 <?php function find_hours($date1, $date2) { return floor(abs(strtotime($date1) - strtotime($date2)) / (60*60)); } echo find_hours("March 20 2006 22:00", "March 21 2006 19:00")."<br>"; //output- 21 echo find_hours("March 20 2006 20:00", "21.2.2005 13:37")."<br>"; //output- 9414 echo find_hours("2.12.2006 3PM", "2/5/07 19:15"); //output- 1564 ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/37153-check-how-many-times-some-houer-pass-between-2-diff-dates/#findComment-177509 Share on other sites More sharing options...
arikflorida Posted February 5, 2007 Author Share Posted February 5, 2007 i don't like to count how many hours passed between 2 dates. i want to know who many times, for exmple the hour 21:00:00 passed between the dates and times. Quote Link to comment https://forums.phpfreaks.com/topic/37153-check-how-many-times-some-houer-pass-between-2-diff-dates/#findComment-177527 Share on other sites More sharing options...
sasa Posted February 5, 2007 Share Posted February 5, 2007 try <?php function no_of_times ($srch,$start,$end) { $start =strtotime($start); $nstart = strtotime(date('Y-m-d ',$start ).$srch); $out = ($start <= $nstart) ? 1 : 0; $out += floor( (strtotime($end) - $nstart) / 86400); return $out; } $srch ='22:00:00'; $start = '2/04/07 22:00:00'; $end = '2/05/07 22:00:00'; echo no_of_times($srch, $start, $end); ?> Quote Link to comment https://forums.phpfreaks.com/topic/37153-check-how-many-times-some-houer-pass-between-2-diff-dates/#findComment-177530 Share on other sites More sharing options...
arikflorida Posted February 6, 2007 Author Share Posted February 6, 2007 thank you very much. its help me a lot... Quote Link to comment https://forums.phpfreaks.com/topic/37153-check-how-many-times-some-houer-pass-between-2-diff-dates/#findComment-177886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.