title: Symfony2 Entity with date, calculate average per day
body: <p>i have an entity Amount</p>
  
  <p>with</p>
  
  <pre><code>/**
   * @var float
   *
   * @ORM\Column(name="value", type="float")
   */
  private $value;
  
  /**
   * @Exclude
   * @Gedmo\Timestampable(on="create")
   * @ORM\Column(name="created_at", type="datetime")
   */
  private $createdAt;
  </code></pre>
  
  <p>and some more fields</p>
  
  <p>I want to calculate the average Value per day</p>
  
  <p>right now i create for everyday a DateTime</p>
  
  <pre><code>    $date=new \DateTime();
      $yesterday = new \ DateTime();
      $yesterday-&gt;modify("- 1 day");
      $beforeYesterday = new \ DateTime();
      $beforeYesterday-&gt;modify("- 2 days");    
      ...
  </code></pre>
  
  <p>and i loop through all amounts </p>
  
  <pre><code>    $averageCounts=[];
  
      foreach ($amounts as $amount) {
          if($amount-&gt;getCreatedAt()-&gt;format("d.m.Y") == $date-&gt;format("d.m.Y") ){
              $averageCounts['today'] += $amount-&gt;getValue();                
          }
  
          if($amount-&gt;getCreatedAt()-&gt;format("d.m.Y") == $yesterday-&gt;format("d.m.Y") ){ 
             $averageCounts['yesterday'] += $amount-&gt;getValue(); 
          }
  
      }
  
      $averagePerDay = ($averageCounts['today'] + $averageCounts['yesterday']) / count($averageCount) ;
  </code></pre>
  
  <p>so its obviuous i cant go on like this, can anybody point me to an elegant way of calculating the average value per day ? </p>