Jump to content

[SOLVED] time problam


redarrow

Recommended Posts

 

advance thank you.

 

i wanted the code to see, if time_now is bigger then the start_time

then tell the user how many hours left from closing.

 

but it seems it wrong is it why?

<?php

$work_start=strtotime("8:00:00am");

if($work_start>=time()){

$hours_left=($work_start) -(time());

echo "There are ".date("h:i:s",$hours_left)." business hours left, untill 8pm closing time";

}else{

echo "Sorry it ".date("h:i:sa")." we are closed";

}

?>

Link to comment
Share on other sites

 

is this codded correctly to get, 12 hours forward?

 

}elseif($work_start+strtotime("+ 12 hours")){

 

  echo "Sorry it ".date("h:i:sa")." we are closed";

 

}

 

 

would this work then?

<?php

$work_start=strtotime("8:00:00");

if($work_start>=strtotime("now")){

$hours_left=($work_start) -(strtotime("now"));

echo "There are ".date("h:i:s",$hours_left)." business hours left, untill 8pm closing time";

}elseif($work_start+strtotime("+ 12 hours")){

echo "Sorry it ".date("h:i:sa")." we are closed";

}

?>

Link to comment
Share on other sites

this must be a winner, does the elseif look ok for 20.00 pm get me mate.

<?php

$work_start=strtotime("8:00:00am");

$work_end=strtotime("20:00:00pm");


if($work_start>=strtotime("now")){

$hours_left=($work_start) -(strtotime("now"));

echo "There are ".date("h:i:s",$hours_left)." business hours left, untill 8pm closing time";

}elseif(strtotime("now")=="$work_end"){

echo "Sorry it ".date("h:i:sa")." we are closed";

}

?>

Link to comment
Share on other sites

<?php

$open=strtotime("8:00:00");
$close = strtotime("20:00:00");
$now = time();

if($now>=$open && $now<=$close) {
echo 'The store closes in ',floor(($close - $now)/(60*60)),':',floor(($close - $now)/(60)),' at ', date('g:i A',$close);
} else {
echo 'Sorry, we are closed!';
}
?>

 

That's how I'd do it... but that's just me. No need for strtotime("now") when you could just do time();

Link to comment
Share on other sites

GRRRRRRRRR phlip beat me to it

<?php

$work_start=strtotime("8:00:00am");

$work_end=strtotime("20:00:00pm");

$curr_time=strtotime("now");

if (
   $work_start <= $curr_time
   &&
   $work_end > $curr_time
   )
{

$hours_left=($work_start) -($curr_time);

echo "There are ".date("h:i:s",$hours_left)." business hours left, untill 8pm closing time";

}else{

echo "Sorry it ".date("h:i:sa")." we are closed";

}

?>

Link to comment
Share on other sites

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.