time - (PHP) Display link ONLY during business hours? -
i trying make live chat link appear on website only during business hours. have code below seems work in afternoon, won't work in morning , i'm not sure why... $start , $end values received mysql database in example i've hard coded them make example simpler.
$linkstatus = "on"; $start = 9:00:00; $end = 23:00:00; $current_time = date('g:i:s'); //9:35:00 if (($start > $current_time) || ($end < $current_time)) { $linkstatus = "off"; } if start time greater current time, business not open yet. if end time less current time, it's after hours. time between 9am , 11pm (23:00) neither 1 of conditions should true, therefore $linkstatus should remain "on". however, not seem doing right now. setting "off".
i've echoed variable above if statement , below can confirm it's if statement causing variable set "off".
as can see code example, i'm not knowledgeable when comes php. appreciated.
date('g:i:s') // 24 hours time without leading 0 hour ...won't sort string, example '9' > '10'.
use 24 hour time leading 0 instead, makes correct sort '09' < '10';
date('h:i:s') // 24 hour time leading 0 hour
Comments
Post a Comment