<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question How to get the Date of the last day of a week given a time stamp in Hadoop Hive? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195086#M83811</link>
    <description />
    <pubDate>Tue, 25 Sep 2018 17:14:57 GMT</pubDate>
    <dc:creator>Gayathridevi</dc:creator>
    <dc:date>2018-09-25T17:14:57Z</dc:date>
    <item>
      <title>How to get the Date of the last day of a week given a time stamp in Hadoop Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195086#M83811</link>
      <description />
      <pubDate>Tue, 25 Sep 2018 17:14:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195086#M83811</guid>
      <dc:creator>Gayathridevi</dc:creator>
      <dc:date>2018-09-25T17:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the Date of the last day of a week given a time stamp in Hadoop Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195087#M83812</link>
      <description>&lt;P&gt;You can write a custom UDF in Hive to pick any day of the week. You can refer lastDay UDF &lt;A href="https://github.com/apache/hive/blob/49abcf767b1da0661e2f4b150c6f80d63cae2ce1/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLastDay.java#L91"&gt;code&lt;/A&gt; as an example&lt;/P&gt;&lt;PRE&gt;// Code in Custom UDF FirstDayOfWeek
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.setTime(formatter.parse("2018-09-16")); // Actual Date string column here
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
System.out.println(calendar.getTime());&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 18:05:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195087#M83812</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2018-09-25T18:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the Date of the last day of a week given a time stamp in Hadoop Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195088#M83813</link>
      <description>&lt;P&gt;Using SQL&lt;/P&gt;&lt;PRE&gt;-- First Day of the week
select date_sub('2018-09-25',pmod(datediff('2018-09-25','1900-01-07'),7));
+-------------+--+
|     _c0     |
+-------------+--+
| 2018-09-23  |
+-------------+--+
-- Last Day of the week
select date_add('2018-09-25',6 - pmod(datediff('2018-09-25','1900-01-07'),7));
+-------------+--+
|     _c0     |
+-------------+--+
| 2018-09-29  |
+-------------+--+&lt;/PRE&gt;&lt;P&gt;If my answer helped to solve your problem, accept the answer. It might help others in the community.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 22:25:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195088#M83813</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2018-09-25T22:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the Date of the last day of a week given a time stamp in Hadoop Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195089#M83814</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/37152/nramanaiah.html" nodeid="37152"&gt;@Naresh P R&lt;/A&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I tried for my scenario I am getting &lt;/P&gt;&lt;P&gt;Also week must start with monday and end with sunday.&lt;/P&gt;&lt;P&gt;select date_sub('2018-09-12',pmod(datediff('2018-09-12','1900-01-07&lt;STRONG&gt;)&lt;/STRONG&gt;,7))&lt;/P&gt;&lt;P&gt;2018-09-09 I am getting sep 9 th which is Sunday.&lt;EM&gt;  &lt;STRONG&gt;but for my scenario the week must start with sep 10 th monday&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;
select date_add('2018-09-12',7 - pmod(datediff('2018-09-12','1900-01-07'),7));&lt;/P&gt;&lt;P&gt;2018-09-16&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 14:04:54 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195089#M83814</guid>
      <dc:creator>Gayathridevi</dc:creator>
      <dc:date>2018-09-28T14:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the Date of the last day of a week given a time stamp in Hadoop Hive?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195090#M83815</link>
      <description>&lt;P&gt;If First day of week should start from Monday, change the subtraction/addition date to 1900-01-08&lt;/P&gt;&lt;PRE&gt;--First day of the week as Monday
select date_sub('2018-09-12',pmod(datediff('2018-09-12','1900-01-08'),7));
+-------------+--+
|     _c0     |
+-------------+--+
| 2018-09-10  |
+-------------+--+
--Last day of the week as Sunday
select date_add('2018-09-12',6 - pmod(datediff('2018-09-12','1900-01-08'),7));
+-------------+--+
|     _c0     |
+-------------+--+
| 2018-09-16  |
+-------------+--+&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 14:21:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-get-the-Date-of-the-last-day-of-a-week-given-a-time/m-p/195090#M83815</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2018-09-28T14:21:00Z</dc:date>
    </item>
  </channel>
</rss>

