title: Switch statement in Javascript with variable comparison
body: <p>I've found a great count up timer on-line, but I need a timer that will show time till a certain date, and once that date-time has past, it'll show how long it's been since that date-time.</p>
  
  <p>I've tried to add a switch statement, but I get all zero's.  </p>
  
  <p>The statement has to change depending on if the count to/from date has passed.</p>
  
  <p>Here's the entire webpage</p>
  
  <pre><code>    &lt;html&gt;
      &lt;head&gt;
   &lt;title&gt;Orders with Approvals Received&lt;/title&gt;
  &lt;meta http-equiv="refresh" content="150"&gt;
  &lt;script&gt;
  /*
   * Basic Count Up from Date and Time
   * Author: @mrwigster / https://guwii.com/bytes/count-date-time-javascript/
   */
  window.onload = function() {
    // Month Day, Year Hour:Minute:Second, id-of-element-container
    countUpFromTime("Feb 6, 2020 15:00:00", 'countup1'); // ****** Change this line!
  };
  function countUpFromTime(countFrom, id) {
    countFrom = new Date(countFrom).getTime();
    var now = new Date(),
        countFrom = new Date(countFrom),
  
        timeDifference = now &lt; countup1 ? (countFrom - now): (now - countFrom);
    //  timeDifference = (now - countFrom); // Count Up
     //  timeDifference = (countFrom - now); //Count Down
  
      var secondsInADay = 60 * 60 * 1000 * 24,
        secondsInAHour = 60 * 60 * 1000;
  
    days = Math.floor(timeDifference / (secondsInADay) * 1);
    hours = Math.floor((timeDifference % (secondsInADay)) / (secondsInAHour) * 1);
    mins = Math.floor(((timeDifference % (secondsInADay)) % (secondsInAHour)) / (60 * 1000) * 1);
    secs = Math.floor((((timeDifference % (secondsInADay)) % (secondsInAHour)) % (60 * 1000)) / 1000 * 1);
  
    var idEl = document.getElementById(id);
    idEl.getElementsByClassName('days')[0].innerHTML = days;
    idEl.getElementsByClassName('hours')[0].innerHTML = hours;
    idEl.getElementsByClassName('minutes')[0].innerHTML = mins;
    idEl.getElementsByClassName('seconds')[0].innerHTML = secs;
  
    clearTimeout(countUpFromTime.interval);
    countUpFromTime.interval = setTimeout(function(){ countUpFromTime(countFrom, id); }, 1000);
  }
  
  &lt;/script&gt;
  &lt;style&gt;
  body {margin:0;
  width: 322px;
  height: 192px;
  }
  .caption
      {
          background-color:BLUE;
          color:white;
          font-family: "Times New Roman", Times, serif;
          font-size: 20px;
          border-style:solid;
          border-width:1px;
          border-color:white;
          text-align:center;
      }
  .countup {
    text-align: center;
    margin-bottom: 0px;
  }
  .countup .timeel {
    display: inline-block;
    padding: 9px;
    background: #151515;
    margin: 0;
    color: white;
    margin-left: 0px;
    border-radius: 5px 0 0 5px;
  }
  .countup span[class*="timeRef"] {
    border-radius: 0 10px 10px 0;
    margin-left: 0;
    background: #e8c152;
    color: black;
  }
  
  &lt;/style&gt;
      &lt;/head&gt;
  &lt;body&gt;
     &lt;thead&gt;
      &lt;div class="caption"&gt;
      &lt;caption&gt;1_Arthur20 Ended&lt;/caption&gt;
      &lt;/div&gt;
      &lt;/thead&gt;
     &lt;tbody&gt;
  &lt;div class="countup" id="countup1"&gt;
    &lt;span class="timeel days"&gt;00&lt;/span&gt;
    &lt;span class="timeel timeRefDays"&gt;D&lt;/span&gt;
    &lt;span class="timeel hours"&gt;00&lt;/span&gt;
    &lt;span class="timeel timeRefHours"&gt;H&lt;/span&gt;
    &lt;span class="timeel minutes"&gt;00&lt;/span&gt;
    &lt;span class="timeel timeRefMinutes"&gt;M&lt;/span&gt;
    &lt;span class="timeel seconds"&gt;00&lt;/span&gt;
    &lt;span class="timeel timeRefSeconds"&gt;S&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class="countup" id="countup1"&gt;
    &lt;span class="timeel days"&gt;2&lt;/span&gt;
    &lt;span class="timeel timeRefDays"&gt;Open&lt;/span&gt;
    &lt;span class="timeel hours"&gt;502&lt;/span&gt;
   &lt;span class="timeel timeRefHours"&gt;Total&lt;/span&gt;
  &lt;/div&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'd appreciate any help that you could give. 
  Thanks,</p>
  
  <p>Edit: I added the line as palash suggested, but one the time has passed it gives me an extra 1 day, 1 hour, 1 minute. So when it's counting down it works great, once it hits all zeros, I get the extra time on the count up. I thought it might be because of timezone, but if I substitute the count up code it works fine. Not certain what's going on with it.</p>
  
  <p>Thanks to everyone that commented.</p>