martin j martin j - 1 month ago 7
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

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

heres my code for christams:

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


btw,
$server_time
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

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.