Show content between time ranges

<?php $theDate = date("H:i"); $date = new DateTime( $theDate ); $date->setTimezone(new DateTimeZone('America/New_York')); echo $date->format('H:i'); $dayName = date('l'); // dayname; ?> <?php // Weekdays if( $dayName !== 'Saturday' || $dayName !== 'Sunday' ) : ?> <?php if(( $theDate >= '08:00' ) && ( $theDate <= '08:36' )) : ?> show dj <?php elseif(( $theDate >= '04:32' ) && ( $theDate <= '04:34' )): ?> Show Other DJ <?php elseif(( $theDate >= '04:35' ) && ( $theDate <= '04:37' )): ?> Show Other Other DJ <?php else: ?> <?php echo $dayName; ?> No DJs <?php endif ?> <?php // Saturday elseif( $dayName == 'Saturday' ) : ?> Saturday Dj <?php // Sunday elseif( $dayName == 'Sunday' ) : ?> Sunday DJ <?php else: ?> <?php endif ?> // New Stuff <?php $dayName = date('l'); // dayname; $theDate = date("H:i"); $now_date = new DateTime( 'now', new DateTimeZone('America/New_York') ); //$date->setTimezone(new DateTimeZone('America/New_York')); $start_dj = new DateTime( 'now', new DateTimeZone('America/New_York') ); $now_date = new DateTime( 'now', new DateTimeZone('America/New_York') ); $current_time = (int) date('Hi'); // echo $date->format('H:i'); $date_int = strtotime($date); //echo $theDate; //echo $theDate; $dj_array=[ [ 'dj_name'=>'DJ One', 'start_time'=>'06:00', 'end_time'=>'10:00', 'show_name'=>'Show Name One' ], [ 'dj_name'=>'DJ Two', 'start_time'=>'10:00', 'end_time'=>'14:00', 'show_name'=>'Show Name Two' ], [ 'dj_name'=>'DJ Three', 'start_time'=>'14:00', 'end_time'=>'17:00', 'show_name'=>'Show Name three' ], ]; $current_dj = null; foreach($dj_array as $dj){ $start_time = new DateTime($dj['start_time'], new DateTimeZone('America/New_York') ); $end_time = new DateTime($dj['end_time'], new DateTimeZone('America/New_York') ); if ($start_time <= $now_date && $now_date <= $end_time){ $current_dj= $dj; break; } } if(!is_null($current_dj)){ foreach($current_dj as $key => $value){ echo $value ; } } ?> // Newest stuff <?php $dayName = date('l'); // dayname; $theDate = date("H:i"); $now_date = new DateTime( 'now', new DateTimeZone('America/New_York') ); //$date->setTimezone(new DateTimeZone('America/New_York')); $start_dj = new DateTime( 'now', new DateTimeZone('America/New_York') ); $now_date = new DateTime( 'now', new DateTimeZone('America/New_York') ); $current_time = date('H:i'); // echo $date->format('H:i'); //$date_int = strtotime($date); //echo $theDate; //echo $theDate; $dj_array=[ [ 'dj_name'=>'DJ One', 'start_time'=>'06:00', 'end_time'=>'10:00', 'show_name'=>'Show Name One' ], [ 'dj_name'=>'DJ Two', 'start_time'=>'10:00', 'end_time'=>'14:00', 'show_name'=>'Show Name Two' ], [ 'dj_name'=>'DJ Three', 'start_time'=>'14:00', 'end_time'=>'23:00', 'show_name'=>'Show Name three' ], ]; $current_dj = null; foreach($dj_array as $dj){ if( $current_time > $dj['start_time'] && $current_time <= $dj['end_time']) { $current_dj = $dj; break; } /* $start_time = new DateTime($dj['start_time'], new DateTimeZone('America/New_York') ); $end_time = new DateTime($dj['end_time'], new DateTimeZone('America/New_York') ); print "<pre>".print_r(array($current_time,date('Hi') ),1)."</pre>"; if ($start_time <= $now_date && $now_date <= $end_time){ $current_dj= $dj; break; } */ } ?> <?php if(!is_null($current_dj)):?> <h1>It's the <?php echo $current_dj['show_name']?>show hosted by <?php echo $current_dj['dj_name']?></h1> <?php endif;?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.