redarrow Posted April 6, 2009 Share Posted April 6, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/ Share on other sites More sharing options...
ToonMariner Posted April 6, 2009 Share Posted April 6, 2009 time() will return the unix epoch timestamp... you either need to convert yoyr 8am into a time stamp or have a look at these http://uk3.php.net/manual/en/datetime.sub.php Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801916 Share on other sites More sharing options...
redarrow Posted April 6, 2009 Author Share Posted April 6, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801921 Share on other sites More sharing options...
ToonMariner Posted April 6, 2009 Share Posted April 6, 2009 sorry completely missed the strtotime!!!! my bad... should do - try it... (i'm too lazy to install php on the machine I am currently on) Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801925 Share on other sites More sharing options...
redarrow Posted April 6, 2009 Author Share Posted April 6, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801927 Share on other sites More sharing options...
Philip Posted April 6, 2009 Share Posted April 6, 2009 <?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(); Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801933 Share on other sites More sharing options...
ToonMariner Posted April 6, 2009 Share Posted April 6, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801938 Share on other sites More sharing options...
redarrow Posted April 6, 2009 Author Share Posted April 6, 2009 thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/152708-solved-time-problam/#findComment-801943 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.