You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "Zachary Tyler Pruitt (JIRA)" <ji...@apache.org> on 2017/12/11 21:09:00 UTC

[jira] [Commented] (HIVE-14653) week value is different between weekofyear(date) and date_format(date, "ww")

    [ https://issues.apache.org/jira/browse/HIVE-14653?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16286570#comment-16286570 ] 

Zachary Tyler Pruitt commented on HIVE-14653:
---------------------------------------------

ISO 8601 specifies that the first day of the week is Monday.
ISO 8601 specifies that the first week of the year will be the week with the first Thursday in it.

WEEKOFYEAR is following ISO 8601.
DATE_FORMAT is not.

{code}
SELECT Calendar_Date,
    DATE_FORMAT(Calendar_Date, 'EEEE') AS Day_Of_Week,
    DATE_FORMAT(Calendar_Date, 'u') AS Day_Of_Week,
    WEEKOFYEAR(Calendar_Date) AS Week_Of_Year_wof,
    DATE_FORMAT(Calendar_Date, 'w') AS Week_Of_Year_df,
    DATE_FORMAT(Calendar_Date, 'W') AS Week_Of_Month
FROM (SELECT EXPLODE(ARRAY('2016-12-31','2017-01-01','2017-01-02')) AS Calendar_Date) c;

+----------------+--------------+--------------+-------------------+------------------+----------------+--+
| calendar_date  | day_of_week  | day_of_week  | week_of_year_wof  | week_of_year_df  | week_of_month  |
+----------------+--------------+--------------+-------------------+------------------+----------------+--+
| 2016-12-31     | Saturday     | 6            | 52                | 53               | 5              |
| 2017-01-01     | Sunday       | 7            | 52                | 1                | 1              |
| 2017-01-02     | Monday       | 1            | 1                 | 1                | 1              |
+----------------+--------------+--------------+-------------------+------------------+----------------+--+
{code}

> week value is different between weekofyear(date) and date_format(date, "ww")
> ----------------------------------------------------------------------------
>
>                 Key: HIVE-14653
>                 URL: https://issues.apache.org/jira/browse/HIVE-14653
>             Project: Hive
>          Issue Type: Bug
>            Reporter: Shawn Zhou
>            Priority: Minor
>




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)