Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/116145-solved-compare-a-time/
Share on other sites

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

/** 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.