noister Posted July 23, 2008 Share Posted July 23, 2008 below is my current code... /** ORDER ONLY BETWEEN 10:00 AM to 8:00 PM **/ $current_time = date("Y-m-d h:i:s a",mktime(date("h")+2,date("i"),date("s"),date("m"),date("j"),date("y"))); // +14 to Philippine standard time $from_time = date("Y-m-d h:i:s a",mktime(10,0,0,date("m"),date("j"),date("y"))); // 10:00 AM $to_time = date("Y-m-d h:i:s a",mktime(20,0,0,date("m"),date("j"),date("y"))); // 8:00 PM //echo "Current: " . $current_time . "<br>From: " . $from_time . "<br>To: " . $to_time; //if($current_time >= $from_time){ if($current_time >= $from_time && $current_time <= $to_time){ //echo "<br>Can order!"; }else{ header("Location: http://www.myjoy.ph/myjoy-offline.html"); //echo "<br>Can't order!"; } For example, if current time is 1:30 PM which "Can Order!" because the range time that allows to order is from 10:00 AM to 8:00 PM. any help really appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/ Share on other sites More sharing options...
LemonInflux Posted July 23, 2008 Share Posted July 23, 2008 So what's wrong with it? ---------------- Now playing: Linkin Park - Enth E Nd (Kutmasta Kurt ft. Motion Man) via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597266 Share on other sites More sharing options...
noister Posted July 23, 2008 Author Share Posted July 23, 2008 that always falls to "Can't Order"... Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597269 Share on other sites More sharing options...
JasonLewis Posted July 23, 2008 Share Posted July 23, 2008 Use strtotime() on the time variables. Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597277 Share on other sites More sharing options...
noister Posted July 23, 2008 Author Share Posted July 23, 2008 below is my current code now...i host it in www.hostmonster.com /** ORDER ONLY BETWEEN 10:00 AM to 8:00 PM **/ echo "Original: " . date("Y-m-d h:i:s a",mktime(date("h"),date("i"),date("s"),date("m"),date("j"),date("y"))) . "<br>"; // orig time $current_time = date("Y-m-d h:i:s a",mktime(date("h")+14,date("i"),date("s")-7,date("m"),date("j"),date("y"))); // +14 to Philippine standard time $from_time = date("Y-m-d h:i:s a",mktime(10,0,0,date("m"),date("j"),date("y"))); // 10:00 AM $to_time = date("Y-m-d h:i:s a",mktime(20,0,0,date("m"),date("j"),date("y"))); // 8:00 PM echo "Current: " . $current_time . "<br>From: " . $from_time . "<br>To: " . $to_time; if($current_time >= $from_time && $current_time <= $to_time){ echo "<br>Can Order!"; }else{ //header("Location: http://www.myjoy.ph/myjoy-offline.html"); echo "<br>Can't Order!"; } http://www.myjoy.ph/delivery/time.php - to see the output Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597281 Share on other sites More sharing options...
JasonLewis Posted July 23, 2008 Share Posted July 23, 2008 Use what I said, or don't use date() when creating your variables. Just keep it as mktime(). Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597284 Share on other sites More sharing options...
noister Posted July 23, 2008 Author Share Posted July 23, 2008 /** ORDER ONLY BETWEEN 10:00 AM to 8:00 PM **/ echo "Original: " . strtotime(mktime(date("h"),date("i"),date("s"),date("m"),date("j"),date("y"))) . " <b>server/www.hostmonster.com Time</b><br>"; // orig time $current_time = strtotime(mktime(date("h")+14,date("i"),date("s")-7,date("m"),date("j"),date("y"))); // +14 to Philippine standard time $from_time = strtotime(mktime(10,0,0,date("m"),date("j"),date("y"))); // 10:00 AM $to_time = strtotime(mktime(20,0,0,date("m"),date("j"),date("y"))); // 8:00 PM echo "Current: " . $current_time . " <b>+14 Philippine Standard Time</b><br>From: " . $from_time . "<br>To: " . $to_time; if($current_time >= $from_time && $current_time <= $to_time){ echo "<br>Can Order!"; }else{ //header("Location: http://www.myjoy.ph/myjoy-offline.html"); echo "<br>Can't Order!"; } output: http://www.myjoy.ph/delivery/time.php Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597292 Share on other sites More sharing options...
JasonLewis Posted July 23, 2008 Share Posted July 23, 2008 You don't need to use strtotime() on mktime() as mktime() already creates a timestamp. Remove the strtotime(). Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597295 Share on other sites More sharing options...
noister Posted July 23, 2008 Author Share Posted July 23, 2008 thanks dude! it works... Quote Link to comment https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/#findComment-597305 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.