title: Calculating average age in Python
body: <p>I am using Django and trying to calculate the average client age, and for some reason this answer is escaping me.  What I want to do is to loop through all clients in a group and get the mean delta of today and their dob.</p>
  
  <p>Here is what the model looks like:</p>
  
  <pre><code>class Client (models.model):
    ...
    dob = models.DateField(
                           null = False
                          )
  </code></pre>
  
  <p>So that I am trying to do something like this:  </p>
  
  <pre><code>def age(self,qrydtm=date.today())
    # here is a method (from funcs.py) that returns a list of dob for the group
    delta = 
    delta_m = ((qrydate.year - self.dob.year)*12)+(qrydate.month - self.dob.month)         
    years = delta_m // 12
    weeks = delta // 7
    months = (delta_m - (years*12))
    if (years &gt; 0):
      return ('%s yr - %s mn' % (years,months))
    else:
      return ('%s wk' % (weeks))  
  </code></pre>
  
  <p>The method I am using, creates a list of dob like this [(datetime.date(1976, 8, 4),), (datetime.date(2005, 8, 8),), (datetime.date(1986, 10, 14),)]</p>