ngng Posted October 16, 2007 Share Posted October 16, 2007 I can calculate if time falls between two ranges, say 01:00:00 and 15:00:00. But I cannot figure out how to calcualte between a time that extends beyond midnight, for example: 15:00:00 and 3:00:00 Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/ Share on other sites More sharing options...
darkfreaks Posted October 16, 2007 Share Posted October 16, 2007 <?php if ($time>15:00:00||$time<3:00:00) {echo " the time Range is .....";}?> Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-370431 Share on other sites More sharing options...
ngng Posted October 17, 2007 Author Share Posted October 17, 2007 <?php if ($time>15:00:00||$time<3:00:00) {echo " the time Range is .....";}?> hmm, that kinda is what i've got...what am I missing <? $today = date('N'); $q = "SELECT * FROM hours WHERE day = $today"; $result = mysql_query($q, $conn); $tmp = mysql_fetch_assoc($result); $o = $tmp['open']; $c = $tmp['close']; if ($now >= $o && $now <= $c ) { $status = "OPEN";} else { $status = "CLOSED";} echo "$name is normally $status at this time!" ?> Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-371968 Share on other sites More sharing options...
darkfreaks Posted October 17, 2007 Share Posted October 17, 2007 <= is bad syntax only used for OOP. if its regular PHP programming you need <?php if ($now >$o||$now<$c) { $status = "OPEN";} else { $status = "CLOSED"; echo "$name is normally $status at this time!";} ?> also paste the full code i have no idea where $now is defined or how it tells i its open or closed Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-371971 Share on other sites More sharing options...
ngng Posted October 18, 2007 Author Share Posted October 18, 2007 <= is bad syntax only used for OOP. if its regular PHP programming you need <?php if ($now >$o||$now<$c) { $status = "OPEN";} else { $status = "CLOSED"; echo "$name is normally $status at this time!";} ?> also paste the full code i have no idea where $now is defined or how it tells i its open or closed good to know, thanks. will that work though, if the times are after midnight? 9PM to 3AM or something? <? date_default_timezone_set('America/Los_Angeles'); $now = date('H:i:s'); $today = date('N'); $q = "SELECT * FROM hours WHERE day = $today"; $result = mysql_query($q, $conn); $tmp = mysql_fetch_assoc($result); //result is returned via MySQL in 24:00 datetime format $o = $tmp['open']; //result is returned via MySQL in 24:00 datetime format $c = $tmp['close']; if ($now >= $o && $now <= $c ) { $status = "OPEN";} else { $status = "CLOSED";} echo "$name is normally $status at this time!" ?> Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-372034 Share on other sites More sharing options...
darkfreaks Posted October 18, 2007 Share Posted October 18, 2007 <?php date_default_timezone_set('America/Los_Angeles'); $now = date('H:i:s'); $today = date('N'); $q = "SELECT * FROM hours WHERE day = $today"; $result = mysql_query($q, $conn); $tmp = mysql_fetch_assoc($result); //result is returned via MySQL in 24:00 datetime format $o = $tmp['open']; //result is returned via MySQL in 24:00 datetime format $c = $tmp['close']; if ($now > $o || $now < $c ) { $status = "OPEN";} else { $status = "CLOSED";} echo "$name is normally $status at this time!" ?> yes this makes since but how does it know when closing or opening is? thats my point it wont work if it doesnt know what the opening or closing times are. Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-372042 Share on other sites More sharing options...
ngng Posted October 18, 2007 Author Share Posted October 18, 2007 yes this makes since but how does it know when closing or opening is? thats my point it wont work if it doesnt know what the opening or closing times are. what do you mean? te opening and closing times are set via mysql Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-372068 Share on other sites More sharing options...
darkfreaks Posted October 18, 2007 Share Posted October 18, 2007 well test it out and tell me what happens ??? Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-372072 Share on other sites More sharing options...
teng84 Posted October 18, 2007 Share Posted October 18, 2007 <= is bad syntax only used for OOP. if its regular PHP programming you need <?php if ($now >$o||$now<$c) { $status = "OPEN";} else { $status = "CLOSED"; echo "$name is normally $status at this time!";} ?> also paste the full code i have no idea where $now is defined or how it tells i its open or closed <= is bad syntax only used for OOP. if its regular PHP programming you need <?php if ($now >$o||$now<$c) { $status = "OPEN";} else { $status = "CLOSED"; echo "$name is normally $status at this time!";} ?> also paste the full code i have no idea where $now is defined or how it tells i its open or closed good to know, thanks. will that work though, if the times are after midnight? 9PM to 3AM or something? <? date_default_timezone_set('America/Los_Angeles'); $now = date('H:i:s'); $today = date('N'); $q = "SELECT * FROM hours WHERE day = $today"; $result = mysql_query($q, $conn); $tmp = mysql_fetch_assoc($result); //result is returned via MySQL in 24:00 datetime format $o = $tmp['open']; //result is returned via MySQL in 24:00 datetime format $c = $tmp['close']; if ($now >= $o && $now <= $c ) { $status = "OPEN";} else { $status = "CLOSED";} echo "$name is normally $status at this time!" ?> LOL funny ;D ;D ;D ;D ;D Quote Link to comment https://forums.phpfreaks.com/topic/73427-calculating-if-current-time-falls-between-a-preset-range/#findComment-372074 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.