Jump to content

[SOLVED] compare a time


noister

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.