Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date-conversion 1

Status
Not open for further replies.

AndreasAuer

IS-IT--Management
Jan 14, 2001
25
AT
I need to convert a weeknumber of a year back to the beginning date of this week

example: '08.2001' -> '19.02.2001'
week 8 of 2001 should return feb 19th of 2001
 
Oracle has a date format for this - 'ww.yyyy'. However using it on an input string generates an ORA-01820 error. You may have already tried this and got the same error.

In the absence of a slick date function, you will have to do some calculations to obtain the desired date. The following is probably close to what you want. It generates the first day of the desired week, with "first day" defined based on Jan. 1. I.e. the first day of each week during the year is the day on which Jan. 1 falls. For 2001 that means Monday.

select trunc(to_date(substr('08.2001',4,4),'yyyy'),'yyyy')
+ 7*(to_number(substr('08.2001',1,2))-1)
from dual;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top