Checking date & time in PHP Goal: To create a countdown to our next available live stream.

Details: We live stream six times a week all (PST).
1. Sunday at 8:00 a.m.
2. Sunday at 10:00 a.m.
3. Sunday at 12:00 p.m.
4. Sunday at 6:30 p.m.
5. Wednesday at 7:00 p.m.
6. Saturday at 10:00 a.m.

My approach: I check what day it is and what time it is then create the countdown to the next stream. 

I'm sure what I have done can be cleaned up and improved, so tell me how.

&lt;?php
// Countdown Stuff
$year = date(Y);
$month = date(m);
$month_day = date(d);
$day = date(w);
$hour = date(G);
$min = date(i);
$addDay = 0;

// It's Sunday
if ( $day == 0 ) {
    if ( $hour &lt; 8 ) {
       $hour = 8;
       $min = 0;
    } 
    else if ( $hour &lt; 10 ) {
       $hour = 10;
       $min = 0;
    } 
    else if ( $hour &lt; 12 ) {
       $hour = 12;
       $min = 0;
    }
    else if ( $hour &lt;= 18 &amp;&amp; $min &lt; 30 ) {
       $hour = 18;
        $min = 30;
    } 
    else {
     $addDay = 3;
       $hour = 19;
       $min = 0;
    }
} 
// It's Monday
else if ( $day == 1 ) {
    $addDay = 2;
      $hour = 19;
      $min = 0;
} 
// It's Tuesday
else if ( $day == 2 ) {
    $addDay = 1;
      $hour = 19;
      $min = 0;
} 
// It's Wednesday
else if ( $day == 3) {

    if ( $hour &lt; 19 ) {
       $hour = 19;
       $min = 0;
    } else {
     $addDay = 3;
       $hour = 10;
       $min = 0;
    }
} 
// It's Thursday
else if ( $day == 4 ) {
    $addDay = 2;
      $hour = 10;
      $min = 0;
} 
// It's Friday
else if ( $day == 5 ) {
    $addDay = 1;
      $hour = 10;
      $min = 0;
} 
// All that's left is Saturday
else {

    if ( $hour &lt; 10 ) {
       $hour = 10;
       $min = 0;
    } else {
     $addDay = 1;
       $hour = 8;
       $min = 0;
    }
}


$build_date = $year . '-' . $month . '-' . $month_day . ' ' . $hour . ':' . $min . ':00';
$date = new DateTime($build_date);

if ( $addDay ) {
    $date-&gt;modify("+$addDay day");
}

$date = strtotime($date-&gt;format("Y-m-d G:i:s"));
$now = strtotime("now");
$count = $date - $now;
?&gt;

&lt;script type="text/javascript"&gt;
var myTime = &lt;?=$count?&gt;;
$('#countdown').countdown({ until: myTime}); 
&lt;/script&gt;
To add to Andrew's answer about taking advantage of what type of timestamps can be creating using strtotime(), your code can be reduced to around 25 lines...

&lt;?php

$schedule = array(
    'this Sunday 8am',
    'this Sunday 10am',
    'this Sunday 12pm',
    'this Sunday 6:30pm',
    'this Wednesday 7pm',
    'this Saturday 10am'
    );

$current_time = strtotime('now');
foreach ($schedule as &amp;$val) {
    $val = strtotime($val);
    // fix schedule to next week if time resolved to the past
    if ($val - $current_time &lt; 0) $val += 604800; 
    }
sort($schedule);
$countdown = $schedule[0] - $current_time;

?&gt;

&lt;script type="text/javascript"&gt;
    var myTime = &lt;?php echo $countdown; // just personally prefer full tags ?&gt;;
    $('#countdown').countdown({ until: myTime}); 
&lt;/script&gt;


To add to visionary-software-solutions' answer, it would be best to store the schedule in a database or a separate xml/text/json/etc type file.  This way, you can have staff simply use an internal webform to change schedules instead of having the PHP dev hard-code the changes every time.  In that webpage, you can allow staff to only select a weekday and time, and have the page translate that into a string usable by strtotime() in this countdown script.

Edit: fixed strtotime() values.  Careful with "this day" vs "next".  For some insight into what type of strings strtotime() can take, see: http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html