martin j martin j - 3 years ago 84
PHP Question

Select 2 dates where an event start and stop

How can I echo something only between two dates? I want to add a

on holidays like christams, but I dont want the
to be gone a split second after the time I set it to echo on. I need to be able to set it like
in some way (if I got that example right).

heres my code for christams:

$christams = date("Y")."-12-23 23:59:59";
if($server_time == $christams){
echo'<div id="snow"></div>';

is defined in head and is currently empty, but its supposed to set the server time since I rather work with 1 timezone then 100

Answer Source

You can simply use strtotime to convert your dates:

$server_time = strtotime("2016-10-12");

$date1 = strtotime("2016-10-10");
$date2 = strtotime("2016-10-14");

if ($server_time >= $date1 && $server_time < $date2) {
    echo'<div id="snow"></div>';
} else {


This example will echo your div.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download