lewel Posted February 17, 2008 Share Posted February 17, 2008 Hi I am trying to write a function that determines if an hour is between other two. let me explain myself say I have 10:45 AM as starting time and 3:30 PM as end time and then I have 8:15 AM and I want to determine if lets say 8:15 AM is between 10:45 AM and 3:30 PM How would I do that in PHP? any Ideas? Thanks in advance. I am trying to write a calendar by the way. Quote Link to comment https://forums.phpfreaks.com/topic/91490-php-time-function/ Share on other sites More sharing options...
Daniel0 Posted February 17, 2008 Share Posted February 17, 2008 Use strtotime() to make it into a timestamp. Then just use the regular lower than and greater than operators. Quote Link to comment https://forums.phpfreaks.com/topic/91490-php-time-function/#findComment-468656 Share on other sites More sharing options...
lewel Posted February 17, 2008 Author Share Posted February 17, 2008 Hey that worked flawlessly thanks alot I was wondering though if I assign 1 to AM and 0 to PM and I add the start time I add the end time and I add the middle time and then compare would I obtain the same result. Let me explain myself $start_time= 10+45+1 $middle_time= 8+15+1 $end_time= 3+30+0 if (($middle_time > $start_time) && ($middle_time < $end_time)) echo "Between <br />"; else echo "Outside <br />"; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/91490-php-time-function/#findComment-468669 Share on other sites More sharing options...
Daniel0 Posted February 17, 2008 Share Posted February 17, 2008 I suppose so (at least in the code you provided), but it would make it less readable for you (after some time where you've forgotten what that specific code does) and for other people. Quote Link to comment https://forums.phpfreaks.com/topic/91490-php-time-function/#findComment-468672 Share on other sites More sharing options...
lewel Posted February 17, 2008 Author Share Posted February 17, 2008 All right thanks for your help greatly appreciated and the answers were incredibly fast thanks again Quote Link to comment https://forums.phpfreaks.com/topic/91490-php-time-function/#findComment-468674 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.