lundi 27 juin 2016

PHP IF/ELSEIF/ELSE for Day and Time

I've got a piece of code on a small system I've put together for work and have got it to almost work perfectly.

The idea is that between 9am and 5pm, Monday to Friday it'll show a form and outside of those times it'll show a message advising them to seek help from another team.

It seemed to work fine today while I've been testing it by changing the times etc.. but then it didn't seem to want to work at all, I seemed to have solved it by adding '09' instead of '9' as the starting time but I've just checked the page it's being used on and the form is showing when in theory it should be the message.

Any ideas?

    <?php
date_default_timezone_set('Europe/London');

$day = date("l"); 
$current_hour = date("g"); 

if ($day == "Monday" && $current_hour >= 09 && $current_hour <= 17) { 
require_once('../forms/function.php');
formcraft(6); 
} 
elseif ($day == "Tuesday" && $current_hour >= 09 && $current_hour <= 17) { 
require_once('../forms/function.php');
formcraft(6); 
} 
elseif ($day == "Wednesday" && $current_hour >= 09 && $current_hour <= 17) { 
require_once('../forms/function.php');
formcraft(6); 
} 
elseif ($day == "Thursday" && $current_hour >= 09 && $current_hour <= 17) { 
require_once('../forms/function.php');
formcraft(6); 
} 
elseif ($day == "Friday" && $current_hour >= 09 && $current_hour <= 17) { 
require_once('../forms/function.php');
formcraft(6); 
} 
else 
{ 
     echo "We're not in the office right now. If your request is urgent, and by that we mean that it will have an immediate impact on our customers and/or people, please forward it to the Duty Managerwho'll know what to do."; 
} 
?>

Aucun commentaire:

Enregistrer un commentaire