Akshay
Akshay

Reputation: 33

Calculate SQL db2 date time difference between below

I have dates column in format like below 2020-06-08 03:54 , 2020-06-08 04:10

I want to calculate time difference between this in SQL dB please Sample excel data Definition Time_cmp= R_date - p_date

R_date | p_ date | time_cmp 2020-06-08 03:54 | 2020-06-08 04:10 | 16

Upvotes: 0

Views: 491

Answers (1)

Paul Vernon
Paul Vernon

Reputation: 3911

Try one of these Db2 functions

DAYS_BETWEEN    (h,l)
HOURS_BETWEEN   (h,l)
MINUTES_BETWEEN (h,l)
MONTHS_BETWEEN  (h,l)
SECONDS_BETWEEN (h,l)
WEEKS_BETWEEN   (h,l)
YEARS_BETWEEN   (h,l)
YMD_BETWEEN     (h,l)

The functions return whole numbers. Put the higher value first to get a +ve number out.

Upvotes: 1

Related Questions