title: How to calculate week ending date in hive using Saturday as week ending date?
body: <p>I had a scenario where I wanted to calculate week ending date (given a date), considering week ends at Saturday. I read some answers but could not find the solution, so I am posting my approach here. Hope it helps somebody like me.</p>
  
  <pre><code>select 
  TransactionDateTime,
  from_unixtime(unix_timestamp(TransactionTime),'u') as wkday,
  date_add (TransactionDateTime,
  case when from_unixtime(unix_timestamp(TransactionTime),'u')=7 then 6 
  when from_unixtime(unix_timestamp(TransactionTime),'u')=1 then 5
  when from_unixtime(unix_timestamp(TransactionTime),'u')=2 then 4
  when from_unixtime(unix_timestamp(TransactionTime),'u')=3 then 3
  when from_unixtime(unix_timestamp(TransactionTime),'u')=4 then 2
  when from_unixtime(unix_timestamp(TransactionTime),'u')=5 then 1
  when from_unixtime(unix_timestamp(TransactionTime),'u')=6 then 0
  end) as UsageWkEndDt
  from TransTable;
  </code></pre>