title: How can I compute week dates in hive?
body: <h2>Background</h2>
  
  <p>Postgresql has the nice function <code>date_trunc()</code> which makes it easy to compute the date a week starts. This is great for aggregations on a week level. eg.</p>
  
  <pre><code>SELECT 
    date_trunc('week', create_date), 
    count(*) 
  FROM ... 
  GROUP BY 1;
  </code></pre>
  
  <p>HiveQL has the function <code>WEEKOFYEAR()</code> that gives you the week number. If you combine this with <code>YEAR()</code> you can make aggregates of the same type as in postgres. </p>
  
  <pre><code>SELECT 
    YEAR(create_date), 
    WEEKOFYEAR(create_date), 
    count(*) 
  FROM ... 
  GROUP BY YEAR(create_date), WEEKOFYEAR(create_date);
  </code></pre>
  
  <p>This is great. But what if I would like the actual date of the week?</p>
  
  <h2>Question</h2>
  
  <p>How can I compute the week date in HiveQL, from either a year and week number or directly from a timestamp?</p>