Reputation: 29
I found this snippet here.
$resttimefrom = 50000; // 5am
$resttimeto = 170000; // 5pm
$currentTime = (int) date('Gis'); // time now
if ($currentTime > $resttimefrom && $currentTime < $resttimeto)
{
// its before 5pm lets do something
}
else
{
// after 5pm sorry
}
This worked perfectly fine but I would like to limit it by date also for the site I am working on I want it to check a timestamp if delivery = tomorrow then they must cancel the order before 5pm the day before.
Upvotes: 2
Views: 802
Reputation: 17894
$timestamp = time();
$date = date("Y-m-d", $timestamp);
$time = date("G", $timestamp);
$tomorrow = date('Y-m-d', strtotime('tomorrow'));
if ($date == $tomorrow && $time > 5 && $time < 17) {
// It is in-between 5am and 5pm tomorrow.
}
Upvotes: 2
Reputation: 2006
if (time() >= strtotime(date('Y-m-d', time()).' 5:00:00') && time() <= strtotime(date('Y-m-d', time()).' 17:00:00')) {
// today between 5AM and 5PM
}
else {
}
Upvotes: 0