I need to show a button on my site only certain days/times
For ex:
Sunday - 8am-8pm
Monday - Dont Show
Tuesday - 7pm-9pm
Wednseday - 4pm-11pm
and so on (repeats every week)
How can i achieve this? (using javascript or php)
I need to show a button on my site only certain days/times
For ex:
Sunday - 8am-8pm
Monday - Dont Show
Tuesday - 7pm-9pm
Wednseday - 4pm-11pm
and so on (repeats every week)
How can i achieve this? (using javascript or php)
This is one way in php:
$show_times = array(
array('sunday 8am', 'sunday 8pm'),
array('tuesday 7pm', 'tuesday 9pm'),
array('wednesday 4pm', 'wednesday 11pm')
);
$now = time();
$show = false;
foreach ($show_times as $time) {
$from = strtotime($time[0]);
$to = strtotime($time[1]);
if ($now >= $from and $now <= $to) {
$show = true;
break;
}
}
if ($show) {
echo '<button>the button</button>';
}