How to calculate the time difference in Hive

I'm a newbie. I have a table of employees with a column indicating the date of joining, and I want to get a list of employees who have joined in the last 3 months. I understand that we can get the current date using from_unixtime (unix_timestamp ()). How to calculate datiff? Is there a built-in DATEDIFF () function, for example, in MS SQL? please advice!

+18
source share
4 answers
datediff(to_date(String timestamp), to_date(String timestamp))

For instance:

SELECT datediff(to_date('2019-08-03'), to_date('2019-08-01')) <= 2;
+43
source

(: , ), "YYYY-MM-DD HH: MM: SS '( ) unix_timestamp(), , . ( 60,0, , 3600,0, ..)

:

UNIX_TIMESTAMP('2017-12-05 10:01:30') - UNIX_TIMESTAMP('2017-12-05 10:00:00') AS time_diff -- This will return 90 (seconds). Unix_timestamp converts string dates into BIGINTs. 

, unix_timestamp() , , : https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions

+3

select * from employee where month(current_date)-3 = month(joining_date)
0
source

All Articles