Convert decimal year to date

喜夏-厌秋 提交于 2019-12-01 12:24:18

If you start from the assumption that the decimal portion was calculated according to the number of days in the given year (i.e. 365 or 366 depending on whether it was a leap year), you could do something like this:

with
 q1 as (select 2003.024658 d from dual)
,q2 as (select d
              ,mod(d,1) as decimal_portion
              ,to_date(to_char(d,'0000')||'0101','YYYYMMDD')
               as jan01
        from q1)
,q3 as (select q2.*
              ,add_months(jan01,12)-jan01 as days_in_year
        from q2)
select d
      ,decimal_portion * days_in_year as days
      ,jan01 + (decimal_portion * days_in_year) as result
from   q3;

d: 2003.024658
days: 9.00017
result: 10-JAN-2003 12:00am
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!