Showing posts with label TO_CHAR. Show all posts
Showing posts with label TO_CHAR. Show all posts

Tuesday 17 June 2014

Find position of current day in a year (Oracle SQL)

---Find the day against any number

select to_date('365','ddd') find_date from dual;

SQL> select to_date('365','ddd') find_date from dual;

FIND_DATE
---------
31-DEC-14

SQL> select to_date('366','ddd') find_date from dual;
select to_date('366','ddd') find_date from dual
               *
ERROR at line 1:
ORA-01848: day of year must be between 1 and 365 (366 for leap year)


Note: ORA-01848: day of year must be between 1 and 365 (366 for leap year)

---Find position of current day in a year

select to_char(sysdate,'ddd') postion from dual;

POSITION
---
168