Reputation: 155
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.
Upvotes: 10
Views: 24121
Reputation: 31
Use sql select trunc(sysdate)+1 - trunc(sysdate,'yyyy') from dual
. you will get an even number
Upvotes: 1
Reputation: 146500
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)
Upvotes: 16
Reputation: 227
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.
Upvotes: 4