Jump to content

if between two days


timmah1

Recommended Posts

I'm trying to figure out if today's current date and time falls between Mon & Fri, but so far, I can't get it to work.

Can anybody look at my code and see what I'm doing wrong?

 

<?php
$day_start = date('D h:i a', strtotime("Mon 05:30"));
$day_end = date('D h:i a', strtotime("Fri 10:00"));
$day_current = date('D h:i a', strtotime("+1 hours"));

if (($day_current > $day_start) && ($day_current < $day_end))
{
echo "yup";
}
else {
echo "nope";
}
?>

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/229979-if-between-two-days/
Share on other sites

If you use a date() format string of 'w H:i' you can probably get your code to work. 'D' won't work because you cannot compare the day names directly and 'h' won't work because you must have the same number of digits in each number being compared as a string.

Link to comment
https://forums.phpfreaks.com/topic/229979-if-between-two-days/#findComment-1184480
Share on other sites

I'm trying to figure out if today's current date and time falls between Mon & Fri

 

This doesn't make sense.  If you're trying to find out if today's date falls on a week day, what does the time matter?

 

$weekend = array('Sat','Sun');
$today = date('D');
if (!in_array($today, $weekend)){
   echo 'Yup';
}
else {
   echo 'Nope';
}

Link to comment
https://forums.phpfreaks.com/topic/229979-if-between-two-days/#findComment-1184485
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.