Search code examples
sqlhivedatediff

I need to make the difference between two timestamp fields, start and end


I need to make the difference between two timestamp fields, start and end, for example: start_date: 2019-09-20 01:15:00 final_date: 2019-09-20 01:20:15 datediff (end_date, start_date)

the return i get is 0.

I think it's because the day is the same, but I would like to have the differences in minutes, where in this case would be 5 minutes.

Has anyone had this difficulty?


Solution

  • One method is to convert to Unix timestamps:

    select (unix_timestamp(final_date) - unix_timestamp(start_date)) / 60 as diff_minutes