timmah1 Posted March 8, 2011 Share Posted March 8, 2011 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 More sharing options...
bh Posted March 8, 2011 Share Posted March 8, 2011 Hi, comparise the dates with ints (use your strtotime functions to do that) Link to comment https://forums.phpfreaks.com/topic/229979-if-between-two-days/#findComment-1184469 Share on other sites More sharing options...
PFMaBiSmAd Posted March 8, 2011 Share Posted March 8, 2011 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 More sharing options...
HuggieBear Posted March 8, 2011 Share Posted March 8, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.