Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.