title: Mapping Dates to Numbers in Time Series using PHP
body: <p>I'm working on an algorithm that analyzes time series, and I'd like to know if it's safe to give values of <code>[0,1,2,...,n-1,n]</code> to date if the dates are evenly spaced:</p>
  
  <p>For example:</p>
  
  <p>Is it safe to map dates to values this way?</p>
  
  <pre><code>2013-07-01 =&gt; 0
  2013-07-08 =&gt; 1
  2013-07-15 =&gt; 2
  2013-07-22 =&gt; 3
  2013-07-29 =&gt; 4
  </code></pre>
  
  <p>For example, If I'm keeping track of sales per week my database looks like:</p>
  
  <pre><code>+------------+---------+
  |     Date   |  Sales  |
  +------------+---------+
  | 2013-07-01 |   24    |
  +------------+---------+
  | 2013-07-08 |   12    |
  +------------+---------+
  | 2013-07-15 |   25    |
  +------------+---------+
  | 2013-07-22 |   10    |
  +------------+---------+
  | 2013-07-29 |   29    |
  +------------+---------+
  </code></pre>
  
  <p>That would be equivalent to:</p>
  
  <pre><code>P(x,y) = { (0, 24), (1, 12), (2, 25), (3, 10), (4, 29) }
  </code></pre>
  
  <p>This way I will be able to use the formula:</p>
  
  <pre><code>Y2 - Y1
  -------
  X2 - X1
  </code></pre>
  
  <p>or in PHP (my application's language):</p>
  
  <pre><code>function isSeriesIncreasing($points) {
      $x1 = current($points);
      $y1 = key($points);
      $x2 = end($points);
      $y2 = key($points);
      return (($y2 - $y1)/($x2 - $x1) &gt; 0) ? true: false;
  }
  
  $timeSeries = array(24,12,25,10,29);
  
  if( isSeriesIncreasing($timeSeries) ) {
      echo "Sales have been increasing";
  } else {
     echo "Sales have been decreasing";
  }
  </code></pre>
  
  <p>So my question is:</p>
  
  <p>Is it good idea to map dates to numbers in time series? 
  Is there a better way to do this in PHP?</p>
  
  <p>Thanks</p>