Chris Hansen
Chris Hansen

Reputation: 8635

date time comparisons in hive sql

in hive sql I have the following field as date time

date_time
2017-01-01 12:00:00 

min_date
2017-02-01 12:00:00 

can I compare both fields as date_time > min_date

in my sql query?

how do we compare date time in hive sql?

both timestamp types

Upvotes: 2

Views: 3113

Answers (1)

leftjoin
leftjoin

Reputation: 38290

You can compare timestamps or strings if they are in sort-able format like this yyyy-MM-dd HH:mm:ss[.f...]

Demo:

hive> select cast('2017-01-01 12:00:00' as timestamp)>cast('2017-02-01 12:00:00' as timestamp);
OK
false
Time taken: 0.13 seconds, Fetched: 1 row(s)

Example with strings:

hive> select '2017-01-01 12:00:00'>'2017-02-01 12:00:00';
OK
false
Time taken: 1.053 seconds, Fetched: 1 row(s)

Upvotes: 1

Related Questions