0

How can i match particular date format in hive query, as i have to get those rows having date format other than max of rows.

Eg. My max of rows have date format as MM/dd/yyyy and i have to list all rows other than above format

+----------------------------+--------------------------+--------------------+-----------+
| AllocationActBankAccountID | GiftCardActBankAccountID | UpdateTimeStampUtc |   Date    |
+----------------------------+--------------------------+--------------------+-----------+
|                         14 |                       14 | 41:39.8            | 4/19/2016 |
|                         14 |                       14 | 37:16.4            | 4/20/2016 |
|                         14 |                       14 | 52:15.2            | 4/21/2016 |
|                         14 |                       14 | 52:15.2            | 2/11/2019 |
|                         14 |                       14 | 52:15.2            | 12-Feb-19 |*
|                         14 |                       14 | 41:39.8            | 2/13/2019 |
+----------------------------+--------------------------+--------------------+-----------+

I want to get * marked data (Date = 12-Feb-19)

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88

1 Answers1

0
select  *
from    mytable
Where   date not rlike '^([1-9]|1[0-2])/([1-9]|[1-2][0-9]|3[0-1])/(19|20)\\d{2}$'

or

select  *
from    mytable
Where   not
        (
            date rlike '^\\d{1,2}/\\d{1,2}/\\d{4}$'
        and cast(split (date,'/')[0] as int) between 1 and 12
        and cast(split (date,'/')[1] as int) between 1 and 31 
        and cast(split (date,'/')[2] as int) between 1900 and 2099 
        ) 

or

select  date
from    mytable
Where   coalesce(from_unixtime(to_unix_timestamp(date,'M/d/y')),'0000-01-01') 
            not between date '1900-01-01' and date '2099-12-31'
David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88