samg
samg

Reputation: 323

how to convert minutes to days in oracle

How would you convert a number of minutes to number of days? For instance, number of minutes is 20160. Now how do I get number of days based on that using SQL?

Upvotes: 0

Views: 1401

Answers (3)

Matthew McPeak
Matthew McPeak

Reputation: 17924

Only for the sake of completeness: here is a way to do it with Oracle functions. (For people who do not want to just assume that the Earth will continue to rotate at a constant speed for the life of their software.)

select extract(day from numtodsinterval(20160,'MINUTE')) days
from   dual;

This gives full days only, so it's essentially the same as

select floor(20160/(24*60)) days from dual;

Upvotes: 0

George Joseph
George Joseph

Reputation: 5922

--divide by 60 get the number of hours and then by 24 to get the number of days
select 20160/60/24 as days_from_min 
  from dual

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269773

You divide:

select 20160 / (24 * 60) as num_days

This returns a fraction. You can floor() or round() to get a whole number.

Upvotes: 2

Related Questions