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
https://forums.phpfreaks.com/topic/152708-solved-time-problam/
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
https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801921
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
https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801927
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
https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801933
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
https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801938
Share on other sites

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.