Hive: Filtering Data between Specified Dates when Date is a String

后端 未结 6 1409
旧巷少年郎
旧巷少年郎 2021-02-04 02:08

I\'m trying to filter data between September 1st, 2010 and August 31st, 2013 in a Hive table. The column containing the date is in string format (yyyy-mm-dd). I can use month()

6条回答
  •  野性不改
    2021-02-04 03:04

    No need to extract the month and year.Just need to use the unix_timestamp(date String,format String) function.

    For Example:

    select yourdate_column
    from your_table
    where unix_timestamp(yourdate_column, 'yyyy-MM-dd') >= unix_timestamp('2014-06-02', 'yyyy-MM-dd')
    and unix_timestamp(yourdate_column, 'yyyy-MM-dd') <= unix_timestamp('2014-07-02','yyyy-MM-dd')
    order by yourdate_column limit 10; 
    

提交回复
热议问题