Oracle Julian day of year

社会主义新天地 提交于 2019-12-23 07:48:46

问题


how can I select Julian day of year in Oracle database?

I tried: select to_char(sysdate, 'J') from dual; Which gives me the number of days since January 1, 4712 BC. But I would need the number of days since 1.1. of current year.


回答1:


If you check the TO_CHAR (datetime) documentation you get a link to "Format Models" with a comprehensive list of available formats. I guess you want this:

DDD Day of year (1-366)




回答2:


SELECT TO_CHAR(SYSDATE, 'DDD') from DUAL;



回答3:


One way would be to use:

select sysdate - trunc(sysdate,'yyyy') from dual

'Trunc' cuts everything except the year and returns 01/01/2014, subtracted by the sysdate returns numbers of days since 1st of january.




回答4:


Use sql select trunc(sysdate)+1 - trunc(sysdate,'yyyy') from dual. you will get an even number



来源:https://stackoverflow.com/questions/24775362/oracle-julian-day-of-year

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