How to get the difference in dates in minutes using Hive

The query below is my SQL server query, and I want it to convert it to a bush query:

select DATEDIFF([minute], '19000101', '2013-01-01 10:10:10') 
+5
source share
1 answer

You can use unix_timestamp for dates after 1970 :

 SELECT (unix_timestamp('2013-01-01 10:10:10') - unix_timestamp('1970-01-01 00:00:00'))/60 
  • Convert both dates in seconds from 1970-01-01
  • Substract them
  • Divide by 60 to get minutes.

SqlFiddleDemoUsingMySQL

EDIT:

Adding minutes: change date to unixtime -> add var * 60sec -> convert back to date

 SELECT from_unixtime(unix_timestamp('2013-01-01 10:10:10') + 10 * 60) AS result 

SqlFiddleDemoUsingMySQL2

+11
source

Source: https://habr.com/ru/post/1235460/


All Articles